add gateway service
parent
4445d42621
commit
a67e8cc985
@ -0,0 +1,108 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class AddressDataType {
|
||||
private static Map<String,String> tdDataTypeMap = new HashMap<>();
|
||||
private static Map<String,String> mysqlDataTypeMap = new HashMap<>();
|
||||
private static Map<String,Integer> gatewayDataTypeMap = new HashMap<>();
|
||||
static {
|
||||
tdDataTypeMap.put("bool","BOOL");
|
||||
tdDataTypeMap.put("int8","INT");
|
||||
tdDataTypeMap.put("int16","INT");
|
||||
tdDataTypeMap.put("int32","INT");
|
||||
tdDataTypeMap.put("int64","BIGINT");
|
||||
tdDataTypeMap.put("uint8","INT");
|
||||
tdDataTypeMap.put("uint16","INT");
|
||||
tdDataTypeMap.put("uint32","BIGINT");
|
||||
tdDataTypeMap.put("uint64","BIGINT");
|
||||
tdDataTypeMap.put("float32","float");
|
||||
tdDataTypeMap.put("float64","float");
|
||||
tdDataTypeMap.put("string","NCHAR(255)");
|
||||
tdDataTypeMap.put("date","TIMESTAMP");
|
||||
tdDataTypeMap.put("bcd","BINARY(64)");
|
||||
|
||||
gatewayDataTypeMap.put("bool",1);
|
||||
gatewayDataTypeMap.put("int8",2);
|
||||
gatewayDataTypeMap.put("uint8",3);
|
||||
gatewayDataTypeMap.put("int16",4);
|
||||
gatewayDataTypeMap.put("uint16",5);
|
||||
gatewayDataTypeMap.put("int32",6);
|
||||
gatewayDataTypeMap.put("uint32",7);
|
||||
gatewayDataTypeMap.put("int64",8);
|
||||
gatewayDataTypeMap.put("uint64",9);
|
||||
gatewayDataTypeMap.put("float32",10);
|
||||
gatewayDataTypeMap.put("float64",11);
|
||||
gatewayDataTypeMap.put("string",12);
|
||||
gatewayDataTypeMap.put("date",13);
|
||||
gatewayDataTypeMap.put("bcd",14);
|
||||
|
||||
gatewayDataTypeMap.put("Bool",1);
|
||||
gatewayDataTypeMap.put("Int8",2);
|
||||
gatewayDataTypeMap.put("Uint8",3);
|
||||
gatewayDataTypeMap.put("Int16",4);
|
||||
gatewayDataTypeMap.put("Uint16",5);
|
||||
gatewayDataTypeMap.put("Int32",6);
|
||||
gatewayDataTypeMap.put("Uint32",7);
|
||||
gatewayDataTypeMap.put("Int64",8);
|
||||
gatewayDataTypeMap.put("Uint64",9);
|
||||
gatewayDataTypeMap.put("Float32",10);
|
||||
gatewayDataTypeMap.put("Float64",11);
|
||||
gatewayDataTypeMap.put("String",12);
|
||||
gatewayDataTypeMap.put("Date",13);
|
||||
gatewayDataTypeMap.put("Bcd",14);
|
||||
|
||||
gatewayDataTypeMap.put("BOOL",1);
|
||||
gatewayDataTypeMap.put("INT8",2);
|
||||
gatewayDataTypeMap.put("UINT8",3);
|
||||
gatewayDataTypeMap.put("INT16",4);
|
||||
gatewayDataTypeMap.put("UINT16",5);
|
||||
gatewayDataTypeMap.put("INT32",6);
|
||||
gatewayDataTypeMap.put("UINT32",7);
|
||||
gatewayDataTypeMap.put("INT64",8);
|
||||
gatewayDataTypeMap.put("UINT64",9);
|
||||
gatewayDataTypeMap.put("FLOAT32",10);
|
||||
gatewayDataTypeMap.put("FLOAT64",11);
|
||||
gatewayDataTypeMap.put("STRING",12);
|
||||
gatewayDataTypeMap.put("DATE",13);
|
||||
gatewayDataTypeMap.put("BCD",14);
|
||||
|
||||
mysqlDataTypeMap.put("bool","BOOL");
|
||||
mysqlDataTypeMap.put("int8","INT");
|
||||
mysqlDataTypeMap.put("int16","INT");
|
||||
mysqlDataTypeMap.put("int32","INT");
|
||||
mysqlDataTypeMap.put("int64","BIGINT");
|
||||
mysqlDataTypeMap.put("uint8","INT");
|
||||
mysqlDataTypeMap.put("uint16","INT");
|
||||
mysqlDataTypeMap.put("uint32","BIGINT");
|
||||
mysqlDataTypeMap.put("uint64","BIGINT");
|
||||
mysqlDataTypeMap.put("float32","float");
|
||||
mysqlDataTypeMap.put("float64","float");
|
||||
mysqlDataTypeMap.put("string","varchar(255)");
|
||||
mysqlDataTypeMap.put("date","TIMESTAMP");
|
||||
mysqlDataTypeMap.put("bcd","double");
|
||||
}
|
||||
public static Map<String,String> getDataTypeMap(){
|
||||
return tdDataTypeMap;
|
||||
}
|
||||
public static String getTdDataType(String originDataType){
|
||||
return tdDataTypeMap.get(originDataType);
|
||||
}
|
||||
public static String getTMysqlDataType(String originDataType){
|
||||
//return mysqlDataTypeMap.get(originDataType);
|
||||
return "double(8,4)";
|
||||
}
|
||||
public static Map<String,Integer> getGatewayDataTypeMap(){
|
||||
return gatewayDataTypeMap;
|
||||
}
|
||||
public static Integer getGatewayDataTypeMap(String originDataType){
|
||||
return gatewayDataTypeMap.get(originDataType);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.bo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 网关接受的Siemens iopoint实体 启用
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChangeStatus {
|
||||
private String changesStatusID;
|
||||
private String newStatus;
|
||||
private String oldStatus;
|
||||
}
|
||||
@ -0,0 +1,205 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.bo;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.*;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HttpEntity {
|
||||
|
||||
public static List<BasicNameValuePair> getRemoveParam(String ids) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("ids", ids));
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
public static List<BasicNameValuePair> getRemoveSiemens(Integer id) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("ids", id.toString()));
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getPageParam(PageEntity pageEntity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("pageSize", pageEntity.getPageSize()));
|
||||
params.add(new BasicNameValuePair("pageNum", pageEntity.getPageNum()));
|
||||
params.add(new BasicNameValuePair("orderByColumn", pageEntity.getOrderByColumn()));
|
||||
params.add(new BasicNameValuePair("isAsc", pageEntity.getIsAsc()));
|
||||
return params;
|
||||
}
|
||||
public static List<BasicNameValuePair> getPageParamVo(PageEntityByDecice pageEntity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("pageSize", pageEntity.getPageSize()));
|
||||
params.add(new BasicNameValuePair("pageNum", pageEntity.getPageNum()));
|
||||
params.add(new BasicNameValuePair("orderByColumn", pageEntity.getOrderByColumn()));
|
||||
params.add(new BasicNameValuePair("isAsc", pageEntity.getIsAsc()));
|
||||
params.add(new BasicNameValuePair("deviceID", pageEntity.getDeviceID()));
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getParam(DeviceSiemensEntity entity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("deviceConfigID", entity.getDeviceConfigID()));
|
||||
params.add(new BasicNameValuePair("deviceID", entity.getDeviceID()));
|
||||
params.add(new BasicNameValuePair("deviceName", entity.getDeviceName()));
|
||||
params.add(new BasicNameValuePair("localPersistent", entity.getLocalPersistent()));
|
||||
params.add(new BasicNameValuePair("rateCount", entity.getRateCount().toString()));
|
||||
params.add(new BasicNameValuePair("siemensConnectParam", entity.getSiemensConnectParam()));
|
||||
params.add(new BasicNameValuePair("siemensSeries", entity.getSiemensSeries()));
|
||||
params.add(new BasicNameValuePair("uploadRate", entity.getUploadRate()));
|
||||
params.add(new BasicNameValuePair("pageSize", entity.getReadRepeatValue().toString()));
|
||||
params.add(new BasicNameValuePair("pageNum", entity.getWriteRepeatValue().toString()));
|
||||
params.add(new BasicNameValuePair("ReadCron", entity.getReadCron()));
|
||||
params.add(new BasicNameValuePair("ReadCronType", entity.getReadCronType()));
|
||||
params.add(new BasicNameValuePair("ReadRepeatUnit", entity.getReadRepeatUnit()));
|
||||
params.add(new BasicNameValuePair("WriteCron", entity.getWriteCron()));
|
||||
params.add(new BasicNameValuePair("WriteCronType", entity.getWriteCronType()));
|
||||
params.add(new BasicNameValuePair("WriteRepeatUnit", entity.getWriteRepeatUnit()));
|
||||
params.add(new BasicNameValuePair("ids", entity.getWriteRepeatUnit()));
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getParam(DeviceModbusEntity entity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
if (entity.getReadRepeatValue() != null) {
|
||||
params.add(new BasicNameValuePair("pageSize", entity.getReadRepeatValue().toString()));
|
||||
}
|
||||
if (entity.getWriteRepeatValue() != null) {
|
||||
params.add(new BasicNameValuePair("pageNum", entity.getWriteRepeatValue().toString()));
|
||||
}
|
||||
if (entity.getDeviceConfigID() != null) {
|
||||
params.add(new BasicNameValuePair("orderByColumn", entity.getDeviceConfigID()));
|
||||
}
|
||||
if (entity.getDeviceId() != null) {
|
||||
params.add(new BasicNameValuePair("deviceID", entity.getDeviceId()));
|
||||
}
|
||||
if (entity.getDeviceName() != null) {
|
||||
params.add(new BasicNameValuePair("deviceName", entity.getDeviceName()));
|
||||
}
|
||||
if (entity.getModbusProtocol() != null) {
|
||||
params.add(new BasicNameValuePair("modbusProtocol", entity.getModbusProtocol()));
|
||||
}
|
||||
if (entity.getModbusPattern() != null) {
|
||||
params.add(new BasicNameValuePair("modbusPattern", entity.getModbusPattern()));
|
||||
}
|
||||
if (entity.getPortName() != null) {
|
||||
params.add(new BasicNameValuePair("portName", entity.getPortName()));
|
||||
}
|
||||
if (entity.getModbusConnectParam() != null) {
|
||||
params.add(new BasicNameValuePair("modbusConnectParam", entity.getModbusConnectParam()));
|
||||
}
|
||||
if (entity.getReadCronType() != null) {
|
||||
params.add(new BasicNameValuePair("readCronType", entity.getReadCronType()));
|
||||
}
|
||||
if (entity.getReadRepeatValue() != null) {
|
||||
params.add(new BasicNameValuePair("readRepeatValue", entity.getReadRepeatValue().toString()));
|
||||
}
|
||||
if (entity.getReadRepeatUnit() != null) {
|
||||
params.add(new BasicNameValuePair("readRepeatUnit", entity.getReadRepeatUnit()));
|
||||
}
|
||||
if (entity.getReadCron() != null) {
|
||||
params.add(new BasicNameValuePair("readCron", entity.getReadCron()));
|
||||
}
|
||||
if (entity.getWriteCronType() != null) {
|
||||
params.add(new BasicNameValuePair("writeCronType", entity.getWriteCronType()));
|
||||
}
|
||||
if (entity.getWriteRepeatValue() != null) {
|
||||
params.add(new BasicNameValuePair("writeRepeatValue", entity.getWriteRepeatValue().toString()));
|
||||
}
|
||||
if (entity.getWriteRepeatUnit() != null) {
|
||||
params.add(new BasicNameValuePair("writeRepeatUnit", entity.getWriteRepeatUnit()));
|
||||
}
|
||||
if (entity.getReadRepeatValue() != null) {
|
||||
params.add(new BasicNameValuePair("writeCron", entity.getWriteCron()));
|
||||
}
|
||||
if (entity.getLocalPersistent() != null) {
|
||||
params.add(new BasicNameValuePair("localPersistent", entity.getLocalPersistent()));
|
||||
}
|
||||
if (entity.getUploadRate() != null) {
|
||||
params.add(new BasicNameValuePair("uploadRate", entity.getUploadRate()));
|
||||
}
|
||||
if (entity.getRateCount() != null) {
|
||||
params.add(new BasicNameValuePair("rateCount", entity.getRateCount().toString()));
|
||||
}
|
||||
if (entity.getModbusReadAddrGap() != null) {
|
||||
params.add(new BasicNameValuePair("modbusReadAddrGap", entity.getModbusReadAddrGap()));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getParam(ModbusPointEntity entity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("deviceConfigContentID", entity.getDeviceConfigContentID()));
|
||||
params.add(new BasicNameValuePair("modbusAddressType", entity.getModbusAddressType()));
|
||||
// params.add(new BasicNameValuePair("modbusFieldAccess", entity.getModbusFieldAccess()));
|
||||
params.add(new BasicNameValuePair("modbusFieldAddress", entity.getModbusFieldAddress()));
|
||||
params.add(new BasicNameValuePair("modbusFieldDataType", entity.getModbusFieldDataType()));
|
||||
params.add(new BasicNameValuePair("modbusFieldName", entity.getModbusFieldName()));
|
||||
params.add(new BasicNameValuePair("modbusFieldOrder", entity.getModbusFieldOrder()));
|
||||
params.add(new BasicNameValuePair("modbusFieldPrecision", entity.getModbusFieldPrecision()));
|
||||
if (entity.getModbusFieldSize()!=null){
|
||||
params.add(new BasicNameValuePair("modbusFieldSize",entity.getModbusFieldSize().toString()));
|
||||
}
|
||||
params.add(new BasicNameValuePair("modbusFieldUnit", entity.getModbusFieldUnit()));
|
||||
params.add(new BasicNameValuePair("modbusSlaveID", entity.getModbusSlaveID()));
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getParam(SiemensPointEntity entity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("deviceConfigContentID", String.valueOf(entity.getDeviceConfigContentID())));
|
||||
params.add(new BasicNameValuePair("siemensFieldAddress", entity.getSiemensFieldAddress()));
|
||||
params.add(new BasicNameValuePair("siemensFieldDataType", entity.getSiemensFieldDataType().toString()));
|
||||
params.add(new BasicNameValuePair("siemensFieldName", entity.getSiemensFieldName()));
|
||||
params.add(new BasicNameValuePair("siemensFieldPrecision",String.valueOf(entity.getSiemensFieldPrecision())));
|
||||
params.add(new BasicNameValuePair("siemensFieldUnit", entity.getSiemensFieldUnit()));
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getParam(DeviceVideoEntity entity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
// params.add(new BasicNameValuePair("deviceConfigID", String.valueOf(entity.getDeviceConfigID())));
|
||||
params.add(new BasicNameValuePair("deviceID", entity.getDeviceID()));
|
||||
params.add(new BasicNameValuePair("videoAddress", entity.getVideoAddress()));
|
||||
params.add(new BasicNameValuePair("serverAddress", entity.getServerAddress()));
|
||||
params.add(new BasicNameValuePair("deviceName",String.valueOf(entity.getDeviceName())));
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getParam(MqttBrokerEntity entity) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("cloudConfigID", entity.getCloudConfigID()));
|
||||
params.add(new BasicNameValuePair("cloudStatus", entity.getCloudStatus()));
|
||||
params.add(new BasicNameValuePair("createTime", entity.getCreateTime()));
|
||||
params.add(new BasicNameValuePair("updateTime", entity.getUpdateTime()));
|
||||
params.add(new BasicNameValuePair("mqttAddress", entity.getMqttAddress()));
|
||||
params.add(new BasicNameValuePair("mqttPassword", entity.getMqttPassword()));
|
||||
params.add(new BasicNameValuePair("mqttUserName", entity.getMqttUserName()));
|
||||
params.add(new BasicNameValuePair("mqttPort", entity.getMqttPort()));
|
||||
params.add(new BasicNameValuePair("mqttPublishTopic", entity.getMqttPublishTopic()));
|
||||
params.add(new BasicNameValuePair("mqttSslFlag", entity.getMqttSslFlag().toString()));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
/*启用模型*/
|
||||
public static List<BasicNameValuePair> getChangestatus(ChangeStatus changeStatus) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("changesStatusID", changeStatus.getChangesStatusID()));
|
||||
params.add(new BasicNameValuePair("newStatus", changeStatus.getNewStatus()));
|
||||
params.add(new BasicNameValuePair("oldStatus", changeStatus.getOldStatus()));
|
||||
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public static List<BasicNameValuePair> getLoginParam(String username,String password) {
|
||||
List<BasicNameValuePair> params = new ArrayList<>();
|
||||
params.add(new BasicNameValuePair("username", username));
|
||||
params.add(new BasicNameValuePair("password", password));
|
||||
return params;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.bo;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ListEntity {
|
||||
String code;
|
||||
String msg;
|
||||
String total;
|
||||
List<JSONObject> rows;
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DeviceSiemensEntity {
|
||||
|
||||
/**数据库id*/
|
||||
String deviceConfigID;
|
||||
/**设备编号*/
|
||||
String deviceID;//71220220500200001
|
||||
|
||||
/**设备名称*/
|
||||
String deviceName;
|
||||
|
||||
/**Siemens系列*/
|
||||
String siemensSeries;
|
||||
|
||||
/**连接参数*/
|
||||
String siemensConnectParam;
|
||||
|
||||
/**读取任务*/
|
||||
String readCronType;//无、频率、定点
|
||||
|
||||
/**频率值*/
|
||||
Integer readRepeatValue;//正整数
|
||||
|
||||
/**读单位*/
|
||||
String readRepeatUnit;//秒、分、时、毫秒
|
||||
|
||||
/**读取任务时间表达式*/
|
||||
String readCron;
|
||||
|
||||
//写入任务时间间隔
|
||||
String writeCronType;
|
||||
|
||||
//写入任务时间间隔
|
||||
Integer writeRepeatValue;
|
||||
|
||||
/**数据库id*/
|
||||
String writeRepeatUnit;
|
||||
/**
|
||||
* 写入任务时间表达式
|
||||
*/
|
||||
String writeCron;
|
||||
|
||||
/**是否持久化*/
|
||||
String localPersistent;
|
||||
|
||||
/**上传*/
|
||||
String uploadRate;
|
||||
|
||||
/**不变次数*/
|
||||
Integer rateCount;
|
||||
|
||||
|
||||
|
||||
/**设备类型*/
|
||||
String deviceType; //siemens、modbus
|
||||
String deviceComm; //1
|
||||
String deviceStatus;//0,notok; 1,ok
|
||||
String createTime;
|
||||
String updateTime;
|
||||
String portName;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DeviceVideoEntity {
|
||||
/**
|
||||
* 网关管理后台的id
|
||||
*/
|
||||
private String deviceConfigID;
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
private String deviceID;
|
||||
/**
|
||||
* 视频地址
|
||||
*/
|
||||
private String videoAddress;
|
||||
/**
|
||||
* 服务地址
|
||||
*/
|
||||
private String serverAddress;
|
||||
/**
|
||||
* 视频名称
|
||||
*/
|
||||
private String deviceName;
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.entity;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 网关接受的iopoint实体
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ModbusPointEntity {
|
||||
|
||||
String deviceConfigContentID;
|
||||
//站号
|
||||
//@Excel(name = "站号")
|
||||
String modbusSlaveID;
|
||||
//地址名称/编码(下发用)
|
||||
//@Excel(name = "地址编码")
|
||||
String modbusFieldName;// json_flag
|
||||
//地址名称 真的名称
|
||||
//@Excel(name = "地址名称")
|
||||
String modbusName;// json_flag
|
||||
//寄存器地址
|
||||
//@Excel(name = "寄存器地址")
|
||||
String modbusFieldAddress;// 111
|
||||
//寄存器地址类型
|
||||
//@Excel(name = "寄存器地址类型")
|
||||
String modbusAddressType;// 1
|
||||
//个数
|
||||
//@Excel(name = "个数")
|
||||
Integer modbusFieldSize;// 2
|
||||
//缩放因子
|
||||
//@Excel(name = "缩放因子")
|
||||
String modbusFieldPrecision;// 1
|
||||
//数据类型
|
||||
//@Excel(name = "数据类型")
|
||||
String modbusFieldDataType;// 1
|
||||
//字节顺序
|
||||
//@Excel(name = "字节顺序")
|
||||
String modbusFieldOrder;//DCBA
|
||||
//单位
|
||||
//@Excel(name = "单位")
|
||||
String modbusFieldUnit;// s
|
||||
//@Excel(name = "机台编码")
|
||||
String equipmentCode;
|
||||
//@Excel(name = "设备编码")
|
||||
String deviceCode;
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class MqttBrokerEntity {
|
||||
|
||||
private String mqttAddress;//ip地址
|
||||
private String mqttPort;//端口
|
||||
private String mqttUserName;//授权账号 一定要授权的
|
||||
private String mqttPassword;//密码
|
||||
private String mqttPublishTopic;//发布主题
|
||||
private Boolean mqttSslFlag; //是否启用ssl
|
||||
|
||||
private String cloudConfigID;
|
||||
private String cloudAddress;
|
||||
private String cloudStatus;
|
||||
private String createTime;
|
||||
private String updateTime;
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PageEntity {
|
||||
|
||||
//String pageSize,String pageNum,String orderByColumn,String isAsc
|
||||
String pageSize; // 10
|
||||
String pageNum; //: 1
|
||||
String orderByColumn; //: updateTime
|
||||
String isAsc; //: asc
|
||||
// String deviceID; //: 设备编码
|
||||
public PageEntity(){
|
||||
this.isAsc = "asc";
|
||||
this.orderByColumn = "updateTime";
|
||||
this.pageSize = "100";
|
||||
this.pageNum = "1";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PageEntityByDecice {
|
||||
|
||||
//String pageSize,String pageNum,String orderByColumn,String isAsc
|
||||
String pageSize; // 10
|
||||
String pageNum; //: 1
|
||||
String orderByColumn; //: updateTime
|
||||
String isAsc; //: asc
|
||||
String deviceID; //: 设备编码
|
||||
public PageEntityByDecice(){
|
||||
this.isAsc = "asc";
|
||||
this.orderByColumn = "updateTime";
|
||||
this.pageSize = "100";
|
||||
this.pageNum = "1";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 网关接受的Siemens iopoint实体
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SiemensPointEntity {
|
||||
/**
|
||||
* 数据库id
|
||||
*/
|
||||
Integer deviceConfigContentID;
|
||||
/**
|
||||
* 地址编码
|
||||
*/
|
||||
//@Excel(name = "地址编码")
|
||||
String siemensFieldName;
|
||||
/**
|
||||
* 地址名称
|
||||
*/
|
||||
//@Excel(name = "地址名称")
|
||||
String siemensName;
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
//@Excel(name = "地址")
|
||||
String siemensFieldAddress;
|
||||
/**
|
||||
* 数据类型(下发用value值)
|
||||
*/
|
||||
Integer siemensFieldDataType;
|
||||
/**
|
||||
* 数据类型名称
|
||||
*/
|
||||
//@Excel(name = "数据类型名称")
|
||||
String siemensFieldDataTypeName;
|
||||
/**
|
||||
* 数据精度
|
||||
*/
|
||||
//@Excel(name = "数据精度")
|
||||
Integer siemensFieldPrecision;
|
||||
/**
|
||||
* 数据单位
|
||||
*/
|
||||
//@Excel(name = "数据单位")
|
||||
String siemensFieldUnit;
|
||||
//@Excel(name = "机台编码")
|
||||
String equipmentCode;
|
||||
//@Excel(name = "设备编码")
|
||||
String deviceCode;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.service;
|
||||
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.bo.ChangeStatus;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.MqttBrokerEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface GatewayMqttService {
|
||||
public void login(String url ,String username ,String password);
|
||||
//获取mqtt主题
|
||||
public List<MqttBrokerEntity> getMqttBrokerEntity(String url, String username , String password);
|
||||
|
||||
//下发单个mqtt主题
|
||||
public int add(MqttBrokerEntity entity, String url);
|
||||
|
||||
//删除mqtt主题
|
||||
public int delete( String url, String ids);
|
||||
|
||||
//启用网关
|
||||
public int changeStatus(ChangeStatus changeStatus, String url);
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.service;
|
||||
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.bo.ChangeStatus;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.DeviceModbusEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.ModbusPointEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface IModbusPointService {
|
||||
|
||||
public void login(String url, String username, String password);
|
||||
|
||||
/*modbus*/
|
||||
//获取设备列表
|
||||
public List<DeviceModbusEntity> getModbusList(String url, String username, String password);
|
||||
//获取指定设备编码列表
|
||||
public List<DeviceModbusEntity> getModbusList(String url, String username, String password,String deviceId);
|
||||
|
||||
//下发单个设备
|
||||
public int add(DeviceModbusEntity entity, String url);
|
||||
|
||||
public int add(List<DeviceModbusEntity> list, String url);
|
||||
|
||||
//删除单个设备
|
||||
public int delete(String url, String ids);
|
||||
|
||||
//启用
|
||||
public int changeStatus(ChangeStatus changeStatus, String url);
|
||||
|
||||
|
||||
//获取设备点位列表
|
||||
public List<ModbusPointEntity> getPointList(String url, String username, String password, String deviceConfigID); //下发点位
|
||||
|
||||
//下发点位
|
||||
public int add(ModbusPointEntity point, String url, String id);
|
||||
|
||||
public int add(List<ModbusPointEntity> list, String address, String deviceConfigID);
|
||||
|
||||
//删除点位
|
||||
public int deletePoint(String url, String ids);
|
||||
|
||||
Integer getPointListByCount(String url, String username, String password, String deviceConfigID);
|
||||
|
||||
List<ModbusPointEntity> getPointListAll(String adminIp, String username, String password, String deviceConfigID);
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.service;
|
||||
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.DeviceVideoEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface IVideoService {
|
||||
public void login(String url, String username, String password);
|
||||
|
||||
|
||||
List<DeviceVideoEntity> getVideoId(String adminIp, String username, String password, String monitorCode);
|
||||
|
||||
|
||||
int deleteByIds(String adminIp, String ids);
|
||||
|
||||
int add(DeviceVideoEntity list, String adminIp);
|
||||
|
||||
int openOrClose(String adminIp, String videoId);
|
||||
}
|
||||
@ -0,0 +1,141 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.service.impl;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.bo.ChangeStatus;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.bo.HttpEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.MqttBrokerEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.service.GatewayMqttService;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.HttpUtils;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.JsonUtils;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.UrlConstans;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class GatewayServiceImpl implements GatewayMqttService {
|
||||
private static final Logger log = LoggerFactory.getLogger(GatewayServiceImpl.class);
|
||||
private String cookie;
|
||||
//先登录
|
||||
@Override
|
||||
public void login(String url ,String username ,String password){
|
||||
// 创建 HttpClient 客户端
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
try {
|
||||
HttpPost httpPost = HttpUtils.getHttpPost(url + UrlConstans.loginUrl, HttpEntity.getLoginParam(username,password));
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
log.debug(EntityUtils.toString(httpResponse.getEntity()));
|
||||
this.cookie = HttpUtils.getCookies(httpResponse);
|
||||
}
|
||||
// 无论如何必须关闭连接
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<MqttBrokerEntity> getMqttBrokerEntity(String url, String username , String password) {
|
||||
|
||||
// 创建 HttpClient 客户端
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
List<MqttBrokerEntity> list = null;
|
||||
try {
|
||||
String getlistUrl = url + UrlConstans.mqtt_list;
|
||||
HttpPost httpPost = HttpUtils.getHttpPost(getlistUrl, null);//检索条件
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
if (httpResponse.getEntity() != null) {
|
||||
String entityStr = EntityUtils.toString(httpResponse.getEntity());
|
||||
list = JsonUtils.toMqttEntityList(entityStr);
|
||||
}
|
||||
}
|
||||
// 无论如何必须关闭连接
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int add(MqttBrokerEntity entity, String address) {
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
HttpPost httpPost = null;
|
||||
|
||||
try {
|
||||
if (entity.getCloudConfigID() != null) {
|
||||
httpPost = HttpUtils.getHttpPost(address + UrlConstans.mqtt_edit, HttpEntity.getParam(entity));
|
||||
} else {
|
||||
httpPost = HttpUtils.getHttpPost(address + UrlConstans.mqtt_add, HttpEntity.getParam(entity));
|
||||
}
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
System.err.println(EntityUtils.toString(httpResponse.getEntity()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete( String address, String ids) {
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
HttpPost httpPost = null;
|
||||
try {
|
||||
httpPost = HttpUtils.getHttpPost(address + UrlConstans.mqtt_remove, HttpEntity.getRemoveParam(ids));//网关上设备的id
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
System.err.println("删除" + httpResponse.getEntity());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int changeStatus(ChangeStatus changeStatus, String address) {
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
HttpPost httpPost = null;
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
try {
|
||||
httpPost = HttpUtils.getHttpPost(address + UrlConstans.mqtt_changestatus, HttpEntity.getChangestatus(changeStatus));
|
||||
// httpPost.setHeader("Cookie", cookie);
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
System.err.println("启用" + httpResponse.getEntity());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,549 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.service.impl;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.bo.HttpEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.DeviceVideoEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.HttpUtils;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.UrlConstans;
|
||||
import cn.iocoder.yudao.module.iot.service.gateway.GatewayService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class TheGatewayServiceImpl {
|
||||
@Autowired
|
||||
private IBeEquipmentsSiemensService beEquipmentsSiemensService;
|
||||
@Autowired
|
||||
private IIoPointService ioPointService;
|
||||
@Autowired
|
||||
private IVideoService videoService;
|
||||
@Autowired
|
||||
private ISiemensPointService siemensPointService;
|
||||
@Autowired
|
||||
private IMqttService mqttService;
|
||||
@Autowired
|
||||
private GatewayService gatewayService;
|
||||
|
||||
//清除原本的西门子设备和点位数据
|
||||
// public void deleteSiemensEntity(BeEquipments equipments) {
|
||||
// siemensPointService.login(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
// List<DeviceSiemensEntity> list = siemensPointService.getSiemensList(equipments.getAdminIp(),
|
||||
// equipments.getUsername(), equipments.getPassword());
|
||||
// if (null != list && list.size() > 0) {
|
||||
// //先清除点位数据
|
||||
// String[] deviceIds = new String[list.size()];
|
||||
// for (int i = 0; i < list.size(); i++) {
|
||||
// deviceIds[i] = list.get(i).getDeviceConfigID();
|
||||
// //删除每个设备下的原有点位
|
||||
// List<SiemensPointEntity> pointList = siemensPointService.getPointList(equipments.getAdminIp(),
|
||||
// list.get(i).getDeviceConfigID(), equipments.getUsername(), equipments.getPassword());
|
||||
// if (pointList != null && pointList.size() > 0) {
|
||||
// String[] addressIds = new String[pointList.size()];
|
||||
// for (int j = 0; j < pointList.size(); j++) {
|
||||
// addressIds[j] = pointList.get(j).getDeviceConfigContentID().toString();
|
||||
// }
|
||||
// //删除点位
|
||||
// siemensPointService.deletePoint(equipments.getAdminIp(), String.join(",", addressIds));
|
||||
// }
|
||||
// }
|
||||
// //再清除设备数据
|
||||
// siemensPointService.delete(equipments.getAdminIp(), String.join(",", deviceIds));
|
||||
// }
|
||||
// }
|
||||
|
||||
//清除指定原本的西门子设备和点位数据
|
||||
public void deleteSiemensEntity(GatewayDO gatewayDO, String deviceCode) {
|
||||
siemensPointService.login(gatewaysMessage.getAdminIp(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword());
|
||||
List<DeviceSiemensEntity> list = siemensPointService.getSiemensList(gatewaysMessage.getAdminIp(),
|
||||
gatewaysMessage.getUsername(), gatewaysMessage.getPassword(), deviceId);
|
||||
if (null != list && list.size() > 0) {
|
||||
//先清除点位数据
|
||||
String[] deviceIds = new String[list.size()];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
deviceIds[i] = list.get(i).getDeviceConfigID();
|
||||
//删除每个设备下的原有点位
|
||||
List<SiemensPointEntity> pointList = siemensPointService.getPointListAll(gatewaysMessage.getAdminIp(),
|
||||
list.get(i).getDeviceConfigID(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword());
|
||||
if (pointList != null && pointList.size() > 0) {
|
||||
String[] addressIds = new String[pointList.size()];
|
||||
for (int j = 0; j < pointList.size(); j++) {
|
||||
addressIds[j] = pointList.get(j).getDeviceConfigContentID().toString();
|
||||
}
|
||||
//删除点位
|
||||
siemensPointService.deletePoint(gatewaysMessage.getAdminIp(), String.join(",", addressIds));
|
||||
}
|
||||
}
|
||||
//再清除设备数据
|
||||
siemensPointService.delete(gatewaysMessage.getAdminIp(), String.join(",", deviceIds));
|
||||
}
|
||||
}
|
||||
|
||||
//查询西门子设备列表 并新增
|
||||
// public void addSiemensEntity(BeEquipments equipments) {
|
||||
// siemensPointService.login(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
// //根据机台编号查询设备
|
||||
// BeEquipmentsSiemens bo = new BeEquipmentsSiemens();
|
||||
// bo.setEquipmentsId(equipments.getEquipmentsId());
|
||||
// List<BeEquipmentsSiemens> siemens = beEquipmentsSiemensService.list(beEquipmentsSiemensService.buildQueryWrapper(bo));
|
||||
// if (siemens != null && siemens.size() > 0) {
|
||||
// List<DeviceSiemensEntity> list = new ArrayList<>();
|
||||
// for (BeEquipmentsSiemens siemen : siemens) {
|
||||
// DeviceSiemensEntity deviceSiemensEntity = new DeviceSiemensEntity();
|
||||
// deviceSiemensEntity.setDeviceID(siemen.getDeviceId());
|
||||
// deviceSiemensEntity.setDeviceName(siemen.getDeviceName());
|
||||
// deviceSiemensEntity.setSiemensSeries(siemen.getSiemensSeries());
|
||||
// deviceSiemensEntity.setSiemensConnectParam(siemen.getSiemensConnectParam());
|
||||
// deviceSiemensEntity.setReadCronType(siemen.getReadCronType());
|
||||
// deviceSiemensEntity.setReadRepeatValue(siemen.getReadRepeatValue());
|
||||
// deviceSiemensEntity.setReadRepeatUnit(siemen.getReadRepeatUnit());
|
||||
// deviceSiemensEntity.setReadCron(siemen.getReadCron());
|
||||
// deviceSiemensEntity.setWriteCronType(siemen.getWriteCronType());
|
||||
// deviceSiemensEntity.setWriteRepeatValue(siemen.getWriteRepeatValue());
|
||||
// deviceSiemensEntity.setWriteCron(siemen.getWriteCron());
|
||||
// deviceSiemensEntity.setLocalPersistent(siemen.getLocalPersistent());
|
||||
// deviceSiemensEntity.setUploadRate(siemen.getUploadRate());
|
||||
// deviceSiemensEntity.setRateCount(siemen.getRateCount());
|
||||
// list.add(deviceSiemensEntity);
|
||||
// }
|
||||
// if (list.size() > 0) siemensPointService.add(list, equipments.getAdminIp());
|
||||
// }
|
||||
// }
|
||||
|
||||
//新增西门子设备
|
||||
public void addSiemensEntity(GatewayDO gatewaysMessage, DeviceDO siemens) {
|
||||
siemensPointService.login(gatewaysMessage.getAdminIp(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword());
|
||||
DeviceSiemensEntity deviceSiemensEntity = new DeviceSiemensEntity();
|
||||
deviceSiemensEntity.setDeviceID(siemen.getDeviceId());
|
||||
deviceSiemensEntity.setDeviceName(siemen.getDeviceName());
|
||||
deviceSiemensEntity.setSiemensSeries(siemen.getSiemensSeries());
|
||||
deviceSiemensEntity.setSiemensConnectParam(siemen.getSiemensConnectParam());
|
||||
deviceSiemensEntity.setReadCronType(siemen.getReadCronType());
|
||||
deviceSiemensEntity.setReadRepeatValue(siemen.getReadRepeatValue());
|
||||
deviceSiemensEntity.setReadRepeatUnit(siemen.getReadRepeatUnit());
|
||||
deviceSiemensEntity.setReadCron(siemen.getReadCron());
|
||||
deviceSiemensEntity.setWriteCronType(siemen.getWriteCronType());
|
||||
deviceSiemensEntity.setWriteRepeatValue(siemen.getWriteRepeatValue());
|
||||
deviceSiemensEntity.setWriteCron(siemen.getWriteCron());
|
||||
deviceSiemensEntity.setLocalPersistent(siemen.getLocalPersistent());
|
||||
deviceSiemensEntity.setUploadRate(siemen.getUploadRate());
|
||||
deviceSiemensEntity.setRateCount(siemen.getRateCount());
|
||||
siemensPointService.add(deviceSiemensEntity, gatewaysMessage.getAdminIp());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//下发完成西门子设备后 下发对应设备的点位
|
||||
public void addDeviceSiemensEntity(BeGatewaysMessage gatewaysMessage,String equipmentsId, String deviceId) {
|
||||
siemensPointService.login(gatewaysMessage.getAdminIp(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword());
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceSiemensEntity> siemensList = siemensPointService.getSiemensList(gatewaysMessage.getAdminIp(),
|
||||
gatewaysMessage.getUsername(), gatewaysMessage.getPassword(), deviceId);
|
||||
for (DeviceSiemensEntity deviceSiemensEntity : siemensList) {
|
||||
//根据deviceId 和机台编码查询sql数据库点位信息
|
||||
IoPoint bo = new IoPoint();
|
||||
bo.setDeviceId(deviceSiemensEntity.getDeviceID());
|
||||
bo.setEquipmentsId(equipmentsId);
|
||||
//检索
|
||||
List<IoPoint> points = ioPointService.list(ioPointService.buildQueryWrapper(bo));
|
||||
List<SiemensPointEntity> list = new ArrayList<>();
|
||||
for (IoPoint point : points) {
|
||||
//新增点位
|
||||
SiemensPointEntity siemensPointEntity = new SiemensPointEntity();
|
||||
siemensPointEntity.setSiemensFieldName(point.getPointCode());
|
||||
siemensPointEntity.setSiemensFieldAddress(point.getAddress());
|
||||
Integer dataType = AddressDataType.getGatewayDataTypeMap(point.getDataType());
|
||||
siemensPointEntity.setSiemensFieldDataType(dataType);
|
||||
siemensPointEntity.setSiemensFieldPrecision(point.getSiemensFieldPrecision());
|
||||
siemensPointEntity.setSiemensFieldUnit(point.getUnit());
|
||||
list.add(siemensPointEntity);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
siemensPointService.add(list, gatewaysMessage.getAdminIp(), deviceSiemensEntity.getDeviceConfigID());
|
||||
}
|
||||
}
|
||||
|
||||
//下发完成西门子设备后 下发对应设备的点位
|
||||
public void addDeviceSiemensEntity(BeEquipments equipments) {
|
||||
siemensPointService.login(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceSiemensEntity> siemensList = siemensPointService.getSiemensList(equipments.getAdminIp(),
|
||||
equipments.getUsername(), equipments.getPassword());
|
||||
|
||||
for (DeviceSiemensEntity deviceSiemensEntity : siemensList) {
|
||||
//根据deviceId 和机台编码查询sql数据库点位信息
|
||||
IoPoint bo = new IoPoint();
|
||||
bo.setDeviceId(deviceSiemensEntity.getDeviceID());
|
||||
bo.setEquipmentsId(equipments.getEquipmentsId());
|
||||
//检索
|
||||
List<IoPoint> points = ioPointService.list(ioPointService.buildQueryWrapper(bo));
|
||||
List<SiemensPointEntity> list = new ArrayList<>();
|
||||
for (IoPoint point : points) {
|
||||
//新增点位
|
||||
SiemensPointEntity siemensPointEntity = new SiemensPointEntity();
|
||||
siemensPointEntity.setSiemensFieldName(point.getPointCode());
|
||||
siemensPointEntity.setSiemensFieldAddress(point.getAddress());
|
||||
Integer dataType = AddressDataType.getGatewayDataTypeMap(point.getDataType());
|
||||
siemensPointEntity.setSiemensFieldDataType(dataType);
|
||||
siemensPointEntity.setSiemensFieldPrecision(point.getSiemensFieldPrecision());
|
||||
siemensPointEntity.setSiemensFieldUnit(point.getUnit());
|
||||
list.add(siemensPointEntity);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
siemensPointService.add(list, equipments.getAdminIp(), deviceSiemensEntity.getDeviceConfigID());
|
||||
}
|
||||
}
|
||||
|
||||
//清除原本的Modbus设备数据
|
||||
public void deleteModbusEntity(BeEquipments equipments) {
|
||||
modbusPointService.login(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
List<DeviceModbusEntity> list = modbusPointService.getModbusList(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
if (null != list && list.size() > 0) {
|
||||
//先清除点位数据
|
||||
String[] deviceIds = new String[list.size()];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
deviceIds[i] = list.get(i).getDeviceConfigID();
|
||||
//删除每个设备下的原有点位
|
||||
List<ModbusPointEntity> pointList = modbusPointService.getPointList(equipments.getAdminIp(),
|
||||
equipments.getUsername(), equipments.getPassword(), list.get(i).getDeviceConfigID());
|
||||
if (pointList != null && pointList.size() > 0) {
|
||||
String[] addressIds = new String[pointList.size()];
|
||||
for (int j = 0; j < pointList.size(); j++) {
|
||||
addressIds[j] = pointList.get(j).getDeviceConfigContentID().toString();
|
||||
}
|
||||
//删除点位数据
|
||||
modbusPointService.deletePoint(equipments.getAdminIp(), String.join(",", addressIds));
|
||||
}
|
||||
}
|
||||
//再清除设备数据
|
||||
modbusPointService.delete(equipments.getAdminIp(), String.join(",", deviceIds));
|
||||
}
|
||||
}
|
||||
|
||||
//清除原本的Modbus设备数据
|
||||
public void deleteModbusEntity(BeGatewaysMessage gatewaysMessage, String deviceId) {
|
||||
modbusPointService.login(gatewaysMessage.getAdminIp(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword());
|
||||
List<DeviceModbusEntity> list = modbusPointService.getModbusList(gatewaysMessage.getAdminIp(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword(), deviceId);
|
||||
if (null != list && list.size() > 0) {
|
||||
//先清除点位数据
|
||||
String[] deviceIds = new String[list.size()];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
deviceIds[i] = list.get(i).getDeviceConfigID();
|
||||
//删除每个设备下的原有点位
|
||||
List<ModbusPointEntity> pointList = modbusPointService.getPointListAll(gatewaysMessage.getAdminIp(),
|
||||
gatewaysMessage.getUsername(), gatewaysMessage.getPassword(), list.get(i).getDeviceConfigID());
|
||||
if (pointList != null && pointList.size() > 0) {
|
||||
String[] addressIds = new String[pointList.size()];
|
||||
for (int j = 0; j < pointList.size(); j++) {
|
||||
addressIds[j] = pointList.get(j).getDeviceConfigContentID();
|
||||
}
|
||||
//删除点位数据
|
||||
modbusPointService.deletePoint(gatewaysMessage.getAdminIp(), String.join(",", addressIds));
|
||||
}
|
||||
}
|
||||
//再清除设备数据
|
||||
modbusPointService.delete(gatewaysMessage.getAdminIp(), String.join(",", deviceIds));
|
||||
}
|
||||
}
|
||||
|
||||
public void addModbusEntity(BeEquipments equipments) {
|
||||
modbusPointService.login(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
BeEquipmentsModbus bo = new BeEquipmentsModbus();
|
||||
bo.setEquipmentsId(equipments.getEquipmentsId());
|
||||
List<BeEquipmentsModbus> modbuses = beEquipmentsModbusService.list(beEquipmentsModbusService.buildQueryWrapper(bo));
|
||||
List<DeviceModbusEntity> list = new ArrayList<>();
|
||||
if (modbuses != null && modbuses.size() > 0) {
|
||||
for (BeEquipmentsModbus modbus : modbuses) {
|
||||
DeviceModbusEntity deviceModbusEntity = new DeviceModbusEntity();
|
||||
deviceModbusEntity.setEquipmentsId(modbus.getEquipmentsId());
|
||||
deviceModbusEntity.setDeviceId(modbus.getDeviceId());
|
||||
deviceModbusEntity.setDeviceName(modbus.getDeviceName());
|
||||
deviceModbusEntity.setModbusProtocol(modbus.getModbusProtocol());
|
||||
deviceModbusEntity.setModbusPattern(modbus.getModbusPattern());
|
||||
deviceModbusEntity.setPortName(modbus.getPortName());
|
||||
deviceModbusEntity.setModbusConnectParam(modbus.getModbusConnectParam());
|
||||
deviceModbusEntity.setReadCronType(modbus.getReadCronType());
|
||||
deviceModbusEntity.setReadRepeatValue(modbus.getReadRepeatValue());
|
||||
deviceModbusEntity.setReadRepeatUnit(modbus.getReadRepeatUnit());
|
||||
deviceModbusEntity.setReadCron(modbus.getReadCron());
|
||||
deviceModbusEntity.setWriteCronType(modbus.getWriteCronType());
|
||||
deviceModbusEntity.setWriteRepeatValue(modbus.getWriteRepeatValue());
|
||||
deviceModbusEntity.setWriteRepeatUnit(modbus.getWriteRepeatUnit());
|
||||
deviceModbusEntity.setWriteCron(modbus.getWriteCron());
|
||||
deviceModbusEntity.setLocalPersistent(modbus.getLocalPersistent());
|
||||
deviceModbusEntity.setUploadRate(modbus.getUploadRate());
|
||||
deviceModbusEntity.setRateCount(modbus.getRateCount());
|
||||
deviceModbusEntity.setModbusReadAddrGap(modbus.getModbusReadAddrGap());
|
||||
list.add(deviceModbusEntity);
|
||||
//mob 下发失败 {"code":500,"msg":"该串口已经配置"}
|
||||
}
|
||||
if (list.size() > 0) modbusPointService.add(list, equipments.getAdminIp());
|
||||
}
|
||||
}
|
||||
|
||||
public void addModbusEntity(BeGatewaysMessage gatewaysMessage, BeEquipmentsModbus modbus) {
|
||||
DeviceModbusEntity deviceModbusEntity = new DeviceModbusEntity();
|
||||
deviceModbusEntity.setEquipmentsId(modbus.getEquipmentsId());
|
||||
deviceModbusEntity.setDeviceId(modbus.getDeviceId());
|
||||
deviceModbusEntity.setDeviceName(modbus.getDeviceName());
|
||||
deviceModbusEntity.setModbusProtocol(modbus.getModbusProtocol());
|
||||
deviceModbusEntity.setModbusPattern(modbus.getModbusPattern());
|
||||
deviceModbusEntity.setPortName(modbus.getPortName());
|
||||
deviceModbusEntity.setModbusConnectParam(modbus.getModbusConnectParam());
|
||||
deviceModbusEntity.setReadCronType(modbus.getReadCronType());
|
||||
deviceModbusEntity.setReadRepeatValue(modbus.getReadRepeatValue());
|
||||
deviceModbusEntity.setReadRepeatUnit(modbus.getReadRepeatUnit());
|
||||
deviceModbusEntity.setReadCron(modbus.getReadCron());
|
||||
deviceModbusEntity.setWriteCronType(modbus.getWriteCronType());
|
||||
deviceModbusEntity.setWriteRepeatValue(modbus.getWriteRepeatValue());
|
||||
deviceModbusEntity.setWriteRepeatUnit(modbus.getWriteRepeatUnit());
|
||||
deviceModbusEntity.setWriteCron(modbus.getWriteCron());
|
||||
deviceModbusEntity.setLocalPersistent(modbus.getLocalPersistent());
|
||||
deviceModbusEntity.setUploadRate(modbus.getUploadRate());
|
||||
deviceModbusEntity.setRateCount(modbus.getRateCount());
|
||||
deviceModbusEntity.setModbusReadAddrGap(modbus.getModbusReadAddrGap());
|
||||
//mob 下发失败 {"code":500,"msg":"该串口已经配置"}
|
||||
modbusPointService.add(deviceModbusEntity, gatewaysMessage.getAdminIp());
|
||||
}
|
||||
|
||||
public void addDeviceModbusEntity(BeEquipments equipments) {
|
||||
modbusPointService.login(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceModbusEntity> modbusPointList = modbusPointService.getModbusList(equipments.getAdminIp(), equipments.getUsername(), equipments.getPassword());
|
||||
for (DeviceModbusEntity deviceModbusEntity : modbusPointList) {
|
||||
//根据deviceId 和机台编码查询sql数据库点位信息
|
||||
IoPoint bo = new IoPoint();
|
||||
bo.setDeviceId(deviceModbusEntity.getDeviceId());
|
||||
bo.setEquipmentsId(equipments.getEquipmentsId());
|
||||
List<IoPoint> points = ioPointService.list(ioPointService.buildQueryWrapper(bo));
|
||||
List<ModbusPointEntity> list = new ArrayList<>();
|
||||
for (IoPoint point : points) {
|
||||
//新增点位
|
||||
ModbusPointEntity modbusPointEntity = new ModbusPointEntity();
|
||||
modbusPointEntity.setModbusSlaveID(point.getModbusSlaveId());
|
||||
modbusPointEntity.setModbusFieldName(point.getPointName());
|
||||
modbusPointEntity.setModbusFieldAddress(point.getModbusFieldAddress());
|
||||
modbusPointEntity.setModbusAddressType(point.getModbusAddressType());
|
||||
modbusPointEntity.setModbusFieldSize(point.getModbusFieldSize());
|
||||
modbusPointEntity.setModbusFieldPrecision(point.getModbusFieldPrecision());
|
||||
modbusPointEntity.setModbusFieldDataType(point.getDataType());
|
||||
modbusPointEntity.setModbusFieldOrder(point.getModbusFieldOrder());
|
||||
modbusPointEntity.setModbusFieldUnit(point.getUnit());
|
||||
list.add(modbusPointEntity);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
modbusPointService.add(list, equipments.getAdminIp(), deviceModbusEntity.getDeviceConfigID());
|
||||
}
|
||||
}
|
||||
|
||||
public void addDeviceModbusEntity(BeGatewaysMessage gatewaysMessage,String equipmentsId, String deviceId) {
|
||||
modbusPointService.login(gatewaysMessage.getAdminIp(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword());
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceModbusEntity> modbusPointList = modbusPointService.getModbusList(gatewaysMessage.getAdminIp(), gatewaysMessage.getUsername(), gatewaysMessage.getPassword(), deviceId);
|
||||
for (DeviceModbusEntity deviceModbusEntity : modbusPointList) {
|
||||
//根据deviceId 和机台编码查询sql数据库点位信息
|
||||
IoPoint bo = new IoPoint();
|
||||
bo.setDeviceId(deviceModbusEntity.getDeviceId());
|
||||
bo.setEquipmentsId(equipmentsId);
|
||||
List<IoPoint> points = ioPointService.list(ioPointService.buildQueryWrapper(bo));
|
||||
List<ModbusPointEntity> list = new ArrayList<>();
|
||||
for (IoPoint point : points) {
|
||||
//新增点位
|
||||
ModbusPointEntity modbusPointEntity = new ModbusPointEntity();
|
||||
modbusPointEntity.setModbusSlaveID(point.getModbusSlaveId());
|
||||
modbusPointEntity.setModbusFieldName(point.getPointCode());
|
||||
modbusPointEntity.setModbusFieldAddress(point.getModbusFieldAddress());
|
||||
modbusPointEntity.setModbusAddressType(point.getModbusAddressType());
|
||||
modbusPointEntity.setModbusFieldSize(point.getModbusFieldSize());
|
||||
modbusPointEntity.setModbusFieldPrecision(point.getModbusFieldPrecision());
|
||||
modbusPointEntity.setModbusFieldDataType(point.getDataType());
|
||||
modbusPointEntity.setModbusFieldOrder(point.getModbusFieldOrder());
|
||||
modbusPointEntity.setModbusFieldUnit(point.getUnit());
|
||||
list.add(modbusPointEntity);
|
||||
}
|
||||
if (list.size() > 0)
|
||||
modbusPointService.add(list, gatewaysMessage.getAdminIp(), deviceModbusEntity.getDeviceConfigID());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下发mqtt主题
|
||||
* 1拿到列表
|
||||
* 2停用
|
||||
* 3删除
|
||||
* 4新增
|
||||
* 5启用
|
||||
*/
|
||||
public void deleteMqttEntity(BeEquipments equipments) {
|
||||
//modbusPointService.login(equipments.getAdminIp(),equipments.getUsername(),equipments.getPassword());
|
||||
List<MqttBrokerEntity> mqttBrokerEntity = mqttService.getMqttBrokerEntity(equipments.getAdminIp(),
|
||||
equipments.getUsername(), equipments.getPassword());
|
||||
for (MqttBrokerEntity brokerEntity : mqttBrokerEntity) {
|
||||
mqttService.delete(equipments.getAdminIp(), brokerEntity.getCloudConfigID());
|
||||
}
|
||||
}
|
||||
|
||||
/***启用设备 */
|
||||
public void changeStatus(BeGatewaysMessage gatewaysMessage, String deviceId, String type) {
|
||||
List<String> deviceIds = new ArrayList<>();
|
||||
if (type.equals("modbus")) {
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceModbusEntity> modbusPointList = modbusPointService.getModbusList(gatewaysMessage.getAdminIp(),
|
||||
gatewaysMessage.getUsername(), gatewaysMessage.getPassword(), deviceId);
|
||||
for (DeviceModbusEntity entity : modbusPointList) {
|
||||
deviceIds.add(entity.getDeviceConfigID());
|
||||
}
|
||||
}
|
||||
if (type.equals("siemens")) {
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceSiemensEntity> siemensList = siemensPointService.getSiemensList(gatewaysMessage.getAdminIp(),
|
||||
gatewaysMessage.getUsername(), gatewaysMessage.getPassword(), deviceId);
|
||||
|
||||
for (DeviceSiemensEntity entity : siemensList) {
|
||||
deviceIds.add(entity.getDeviceConfigID());
|
||||
}
|
||||
}
|
||||
ChangeStatus changeStatus = new ChangeStatus();
|
||||
changeStatus.setNewStatus("2");
|
||||
changeStatus.setOldStatus("1");
|
||||
siemensPointService.changeStatusDevice(deviceIds, changeStatus, gatewaysMessage.getAdminIp());
|
||||
}
|
||||
|
||||
/***启用设备 */
|
||||
public void changeStatus(BeEquipments equipments) {
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceModbusEntity> modbusPointList = modbusPointService.getModbusList(equipments.getAdminIp(),
|
||||
equipments.getUsername(), equipments.getPassword());
|
||||
/*下发好设备后获取设备列表找点位*/
|
||||
List<DeviceSiemensEntity> siemensList = siemensPointService.getSiemensList(equipments.getAdminIp(),
|
||||
equipments.getUsername(), equipments.getPassword());
|
||||
List<String> deviceIds = new ArrayList<>();
|
||||
for (DeviceModbusEntity entity : modbusPointList) {
|
||||
deviceIds.add(entity.getDeviceConfigID());
|
||||
}
|
||||
for (DeviceSiemensEntity entity : siemensList) {
|
||||
deviceIds.add(entity.getDeviceConfigID());
|
||||
}
|
||||
ChangeStatus changeStatus = new ChangeStatus();
|
||||
changeStatus.setNewStatus("2");
|
||||
changeStatus.setOldStatus("1");
|
||||
siemensPointService.changeStatusDevice(deviceIds, changeStatus, equipments.getAdminIp());
|
||||
}
|
||||
|
||||
public BeEquipments getEquipments(Integer gatewayMessageId) {
|
||||
BeGatewaysMessage gatewaysMessage = gatewaysMessageService.getById(gatewayMessageId);
|
||||
BeEquipments bo = new BeEquipments();
|
||||
bo.setEquipmentsId(gatewaysMessage.getEquipmentId());
|
||||
bo = equipmentsService.getOne(equipmentsService.buildQueryWrapper(bo));
|
||||
return bo;
|
||||
}
|
||||
|
||||
|
||||
/*检测下发数据和实际下发数量是否匹配*/
|
||||
public AjaxResult compare(String url, String username, String password, String deviceId, String equipmentId, String type) {
|
||||
String deviceConfigID = null;
|
||||
Integer pointList = 0;
|
||||
if ("m".equals(type)) {
|
||||
List<DeviceModbusEntity> modbusList = modbusPointService.getModbusList(url, username, password, deviceId);
|
||||
if (modbusList != null && modbusList.size() > 0) {
|
||||
deviceConfigID = modbusList.get(0).getDeviceConfigID();
|
||||
}
|
||||
pointList = modbusPointService.getPointListByCount(url, username, password, deviceConfigID);
|
||||
} else {
|
||||
List<DeviceSiemensEntity> siemensList = siemensPointService.getSiemensList(url, username, password, deviceId);
|
||||
if (siemensList != null && siemensList.size() > 0) {
|
||||
deviceConfigID = siemensList.get(0).getDeviceConfigID();
|
||||
}
|
||||
pointList = siemensPointService.getPointListByCount(url, deviceConfigID, username, password);
|
||||
}
|
||||
//根据deviceId 和机台编码查询sql数据库点位信息
|
||||
IoPoint bo = new IoPoint();
|
||||
bo.setDeviceId(deviceId);
|
||||
bo.setEquipmentsId(equipmentId);
|
||||
List<IoPoint> points = ioPointService.list(ioPointService.buildQueryWrapper(bo));
|
||||
int size = points.size();
|
||||
return size!=pointList?AjaxResult.error("下发失败!应下发" + points.size() + "个地址,实下发" + pointList + "个地址")
|
||||
:AjaxResult.success("下发成功!应下发" + points.size() + "个地址,实下发" + pointList + "个地址");
|
||||
}
|
||||
|
||||
/**网关登录测试*/
|
||||
public CommonResult login(GatewayDO gateway){
|
||||
// 创建 HttpClient 客户端
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
try {
|
||||
HttpPost httpPost = HttpUtils.getHttpPost(
|
||||
gateway.getAdminIp() + UrlConstans.loginUrl,
|
||||
HttpEntity.getLoginParam(gateway.getUsername(),gateway.getPassword()));
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
if (httpResponse.getEntity() != null) {
|
||||
String entityStr = EntityUtils.toString(httpResponse.getEntity());
|
||||
if(entityStr.contains("服务不可用") || entityStr.contains("<!DOCTYPE html>"))
|
||||
return CommonResult.success("网关服务不可用!");
|
||||
ResponseInfo info = JSON.parseObject(entityStr, ResponseInfo.class);
|
||||
if(info.code==0)return CommonResult.success("网关登录测试成功!");
|
||||
}
|
||||
}
|
||||
// 无论如何必须关闭连接
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return CommonResult.error(500,"网关登录测试失败!");
|
||||
}
|
||||
|
||||
public int openOrClose(String adminIp, String username, String password, String monitorCode) {
|
||||
List<DeviceVideoEntity> videoId = videoService.getVideoId(adminIp, username, password, monitorCode);
|
||||
if (videoId != null && videoId.size() > 0) {
|
||||
String[] addressIds = new String[videoId.size()];
|
||||
for (int j = 0; j < videoId.size(); j++) {
|
||||
addressIds[j] = videoId.get(j).getDeviceConfigID();
|
||||
}
|
||||
return videoService.openOrClose(adminIp,String.join(",",addressIds));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class ResponseInfo {
|
||||
int code;
|
||||
String msg;
|
||||
}
|
||||
public void deleteVideo(String adminIp,String username,String password,String monitorCode) {
|
||||
videoService.login(adminIp,username,password);
|
||||
List<DeviceVideoEntity> videoId = videoService.getVideoId(adminIp, username, password, monitorCode);
|
||||
if (videoId != null && videoId.size() > 0) {
|
||||
String[] addressIds = new String[videoId.size()];
|
||||
for (int j = 0; j < videoId.size(); j++) {
|
||||
addressIds[j] = videoId.get(j).getDeviceConfigID();
|
||||
}
|
||||
videoService.deleteByIds(adminIp, String.join(",", addressIds));
|
||||
}
|
||||
}
|
||||
|
||||
public void addVideo(String adminIp,String username,String password, Monitor monitor) {
|
||||
videoService.login(adminIp,username,password);
|
||||
DeviceVideoEntity deviceVideoEntity = new DeviceVideoEntity();
|
||||
deviceVideoEntity.setDeviceID(monitor.getMonitorCode());
|
||||
deviceVideoEntity.setDeviceName(monitor.getMonitorName());
|
||||
deviceVideoEntity.setServerAddress(monitor.getServiceAddress());
|
||||
deviceVideoEntity.setVideoAddress(monitor.getVideoAddress());
|
||||
videoService.add(deviceVideoEntity, adminIp);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,128 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.service.impl;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.bo.HttpEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.DeviceVideoEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.PageEntityByDecice;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.service.IVideoService;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.HttpUtils;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.JsonUtils;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.util.UrlConstans;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.module.iot.framework.gateway.util.HttpUtils.getHttpPost;
|
||||
|
||||
@Service
|
||||
public class VideoServiceImpl implements IVideoService {
|
||||
private static final Logger log = LoggerFactory.getLogger(VideoServiceImpl.class);
|
||||
private String cookie;
|
||||
//先登录
|
||||
@Override
|
||||
public void login(String url ,String username ,String password){
|
||||
// 创建 HttpClient 客户端
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
try {
|
||||
HttpPost httpPost = getHttpPost(url + UrlConstans.loginUrl, HttpEntity.getLoginParam(username,password));
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
log.debug(EntityUtils.toString(httpResponse.getEntity()));
|
||||
this.cookie = HttpUtils.getCookies(httpResponse);
|
||||
}
|
||||
// 无论如何必须关闭连接
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceVideoEntity> getVideoId(String adminIp, String username, String password, String monitorCode) {
|
||||
PageEntityByDecice pageEntity = new PageEntityByDecice();
|
||||
pageEntity.setDeviceID(monitorCode);
|
||||
// 创建 HttpClient 客户端
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
List<DeviceVideoEntity> list = null;
|
||||
try {
|
||||
String getlistUrl = adminIp + UrlConstans.video_list;
|
||||
HttpPost httpPost = getHttpPost(getlistUrl, HttpEntity.getPageParamVo(pageEntity));//检索条件
|
||||
login(adminIp, username, password);
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
if (httpResponse.getEntity() != null) {
|
||||
String entityStr = EntityUtils.toString(httpResponse.getEntity());
|
||||
list = JsonUtils.toVideoEntityList(entityStr);
|
||||
}
|
||||
}
|
||||
// 无论如何必须关闭连接
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteByIds(String adminIp, String ids) {
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
try {
|
||||
HttpPost httpPost = getHttpPost(adminIp + UrlConstans.video_remove, HttpEntity.getRemoveParam(ids));
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int add(DeviceVideoEntity list, String adminIp) {
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
HttpPost httpPost = null;
|
||||
try {
|
||||
httpPost = getHttpPost(adminIp + UrlConstans.video_add, HttpEntity.getParam(list));
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
// 设置 HttpPost 参数
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
log.debug(EntityUtils.toString(httpResponse.getEntity()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int openOrClose(String adminIp, String videoId) {
|
||||
CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault();
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
try {
|
||||
HttpPost httpPost = getHttpPost(adminIp + UrlConstans.video_push_stream, HttpEntity.getRemoveParam(videoId));
|
||||
httpPost.setHeader("Cookie", cookie);
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
HttpUtils.closeHttp(httpClient, httpResponse);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.util;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.bo.ListEntity;
|
||||
import cn.iocoder.yudao.module.iot.framework.gateway.entity.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
|
||||
public static List<SiemensPointEntity> toSiemensPointEntityList(String jsonStr) {
|
||||
List<SiemensPointEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
for (JSONObject json : entity.getRows()) {
|
||||
String obj = json.toJSONString();
|
||||
list.add(JSON.parseObject(obj, SiemensPointEntity.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String toSiemensPointEntityTotal(String jsonStr) {
|
||||
List<SiemensPointEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
return entity.getTotal();
|
||||
}
|
||||
|
||||
public static List<ModbusPointEntity> toModbusPointEntityList(String jsonStr) {
|
||||
List<ModbusPointEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
for (JSONObject json : entity.getRows()) {
|
||||
String obj = json.toJSONString();
|
||||
list.add(JSON.parseObject(obj, ModbusPointEntity.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String toModbusPointEntityTotal(String jsonStr) {
|
||||
List<ModbusPointEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
return entity.getTotal();
|
||||
}
|
||||
|
||||
public static ListEntity toPointEntity(String jsonStr) {
|
||||
return JSON.parseObject(jsonStr, ListEntity.class);
|
||||
}
|
||||
|
||||
public static List<DeviceSiemensEntity> toDeviceSiemensEntityList(String jsonStr) {
|
||||
List<DeviceSiemensEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
for (JSONObject json : entity.getRows()) {
|
||||
String obj = json.toJSONString();
|
||||
list.add(JSON.parseObject(obj, DeviceSiemensEntity.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<DeviceModbusEntity> toDeviceModbusEntityList(String jsonStr) {
|
||||
List<DeviceModbusEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
for (JSONObject json : entity.getRows()) {
|
||||
String obj = json.toJSONString();
|
||||
list.add(JSON.parseObject(obj, DeviceModbusEntity.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<MqttBrokerEntity> toMqttEntityList(String jsonStr) {
|
||||
List<MqttBrokerEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
for (JSONObject json : entity.getRows()) {
|
||||
String obj = json.toJSONString();
|
||||
list.add(JSON.parseObject(obj, MqttBrokerEntity.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<DeviceVideoEntity> toVideoEntityList(String jsonStr) {
|
||||
List<DeviceVideoEntity> list = new ArrayList<>();
|
||||
ListEntity entity = JSON.parseObject(jsonStr, ListEntity.class);
|
||||
for (JSONObject json : entity.getRows()) {
|
||||
String obj = json.toJSONString();
|
||||
list.add(JSON.parseObject(obj, DeviceVideoEntity.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package cn.iocoder.yudao.module.iot.framework.gateway.util;
|
||||
|
||||
public class UrlConstans {
|
||||
|
||||
public static final String loginUrl = "/login";
|
||||
|
||||
/**
|
||||
* mqtt
|
||||
*/
|
||||
public static final String mqtt_add = "/cloud/config/mqtt/add";
|
||||
public static final String mqtt_list = "/cloud/config/mqtt/list";
|
||||
public static final String mqtt_edit = "/cloud/config/mqtt/add";
|
||||
public static final String mqtt_remove = "/cloud/config/remove";
|
||||
public static final String mqtt_changestatus = "/cloud/config/changestatus";//启用
|
||||
|
||||
/***/
|
||||
public static final String siemens_list = "/device/config/siemens/list";
|
||||
public static final String siemens_add = "/device/config/siemens/add";
|
||||
public static final String siemens_edit = "/device/config/siemens/add";
|
||||
public static final String siemens_remove = "/device/config/remove";
|
||||
public static final String siemens_changestatus = "/device/config/changeStatus";//启用
|
||||
|
||||
/**
|
||||
* Video
|
||||
*/
|
||||
public static final String video_list = "/device/config/video/list";
|
||||
public static final String video_add = "/device/config/video/add";
|
||||
// public static final String video_edit = "/device/config/video/add";
|
||||
public static final String video_remove = "/device/config/video/remove";
|
||||
//device/config/video/push/stream/399/?_=1665714825994
|
||||
public static final String video_push_stream = "/device/config/video/push/stream";//推流
|
||||
// public static final String Video_changestatus = "/device/config/changeStatus";//启用
|
||||
|
||||
/**
|
||||
* siemens iopoint list
|
||||
*/
|
||||
public static final String siemens_iopoint_list_r = "/device/config/siemens/contentlist/r/";
|
||||
/**
|
||||
* siemens iopoint add
|
||||
*/
|
||||
//https://71220220500200002.ng.xjzyun.com/device/config/siemens/content/add/r/0/82
|
||||
public static final String siemens_iopoint_add_r = "/device/config/siemens/content/add/r/0/";
|
||||
/**
|
||||
* siemens iopoint list
|
||||
*/
|
||||
public static final String siemens_iopoint_edit_r = "/device/config/siemens/content/add/r/";
|
||||
/**
|
||||
* siemens iopoint list
|
||||
*/
|
||||
public static final String siemens_iopoint_remove_r = "/device/configcontent/remove";
|
||||
|
||||
/**
|
||||
* siemens iopoint list
|
||||
*/
|
||||
public static final String siemens_iopoint_list_w = "/device/config/siemens/contentlist/r/";
|
||||
/**
|
||||
* siemens iopoint add
|
||||
*/
|
||||
public static final String siemens_iopoint_add_w = "/device/config/siemens/content/add/w/0/";
|
||||
/**
|
||||
* siemens iopoint list
|
||||
*/
|
||||
public static final String siemens_iopoint_edit_w = "/device/config/siemens/content/add/w/";
|
||||
/**
|
||||
* siemens iopoint list
|
||||
*/
|
||||
public static final String siemens_iopoint_remove_w = "/device/configcontent/remove";
|
||||
|
||||
/***/
|
||||
public static final String modbus_list = "/device/config/modbus/list";
|
||||
public static final String modbus_add = "/device/config/modbus/add";
|
||||
public static final String modbus_edit = "/device/config/modbus/edit";
|
||||
public static final String modbus_remove = "/device/config/modbus/remove";
|
||||
public static final String modbus_changestatus = "/device/config/changestatus";//启用
|
||||
/**
|
||||
* modbus iopoint list
|
||||
*/
|
||||
public static final String modbus_iopoint_list = "/device/config/modbus/contentlist/r/";
|
||||
/**
|
||||
* modbus iopoint add
|
||||
*/
|
||||
public static final String modbus_iopoint_add_r = "/device/config/modbus/content/add/r/0/";
|
||||
/**
|
||||
* modbus iopoint list
|
||||
*/
|
||||
public static final String modbus_iopoint_edit = "/device/config/modbus/content/add/r/";
|
||||
/**
|
||||
* siemens iopoint list
|
||||
*/
|
||||
public static final String modbus_iopoint_remove = "/device/configcontent/remove";
|
||||
}
|
||||
Loading…
Reference in New Issue