IOT设备
This commit is contained in:
parent
04137f7203
commit
0bf660faf3
|
|
@ -0,0 +1,140 @@
|
||||||
|
package com.bonus.sgzb.common.core.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.bonus.sgzb.common.core.constant.HttpStatus;
|
||||||
|
import com.bonus.sgzb.common.core.constant.UserConstants;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HttpHelper {
|
||||||
|
|
||||||
|
public static String sendHttpPost(String url, String JSONBody) throws Exception {
|
||||||
|
|
||||||
|
System.out.println("JSONBody-=========:" + JSONBody);
|
||||||
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
|
HttpPost httpPost = new HttpPost(url);
|
||||||
|
httpPost.addHeader("Content-Type", "application/json");
|
||||||
|
httpPost.setEntity(new StringEntity(JSONBody));
|
||||||
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||||
|
HttpEntity entity = response.getEntity();
|
||||||
|
String responseContent = EntityUtils.toString(entity, "UTF-8");
|
||||||
|
response.close();
|
||||||
|
httpClient.close();
|
||||||
|
return responseContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String doPost(String urlString,String param) {
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
InputStream is = null;
|
||||||
|
OutputStream os = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
String result = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
// 通过远程url连接对象打开连接
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
// 设置连接请求方式
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
// 设置连接主机服务器超时时间:15000毫秒
|
||||||
|
connection.setConnectTimeout(15000);
|
||||||
|
// 设置读取主机服务器返回数据超时时间:60000毫秒
|
||||||
|
connection.setReadTimeout(60000);
|
||||||
|
|
||||||
|
// 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
// 默认值为:true,当前向远程服务读取数据时,设置为true,该参数可有可无
|
||||||
|
connection.setDoInput(true);
|
||||||
|
// 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。
|
||||||
|
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
// 设置鉴权信息:Authorization: Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0
|
||||||
|
connection.setRequestProperty("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0");
|
||||||
|
// 通过连接对象获取一个输出流
|
||||||
|
os = connection.getOutputStream();
|
||||||
|
// 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的
|
||||||
|
os.write(param.getBytes());
|
||||||
|
// 通过连接对象获取一个输入流,向远程读取
|
||||||
|
if (connection.getResponseCode() == 200) {
|
||||||
|
|
||||||
|
is = connection.getInputStream();
|
||||||
|
// 对输入流对象进行包装:charset根据工作项目组的要求来设置
|
||||||
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
|
|
||||||
|
StringBuffer sbf = new StringBuffer();
|
||||||
|
String temp = null;
|
||||||
|
// 循环遍历一行一行读取数据
|
||||||
|
while ((temp = br.readLine()) != null) {
|
||||||
|
sbf.append(temp);
|
||||||
|
sbf.append("\r\n");
|
||||||
|
}
|
||||||
|
result = sbf.toString();
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
// 关闭资源
|
||||||
|
if (null != br) {
|
||||||
|
try {
|
||||||
|
br.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != os) {
|
||||||
|
try {
|
||||||
|
os.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != is) {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 断开与远程地址url的连接
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getIotToken() {
|
||||||
|
Map<String,Object> map=new HashMap<>();
|
||||||
|
String redisCode = null;
|
||||||
|
map.put("type", UserConstants.IOT_TYPE);
|
||||||
|
map.put("from",UserConstants.IOT_FROM);
|
||||||
|
map.put("username",UserConstants.IOT_USERNAME);
|
||||||
|
//采用md5加密
|
||||||
|
map.put("password",UserConstants.IOT_PASSWORD);
|
||||||
|
String param = JSON.toJSONString(map);
|
||||||
|
String resultUser = HttpHelper.doPost(HttpStatus.LOGIN_URL,param);
|
||||||
|
if (resultUser == null){
|
||||||
|
throw new RuntimeException("返回数据为空!!");
|
||||||
|
}
|
||||||
|
JSONObject object = JSONObject.parseObject(resultUser);
|
||||||
|
if ("0".equals(object.getString("status"))){
|
||||||
|
redisCode = object.getString("token");
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException("返回数据为空!!");
|
||||||
|
}
|
||||||
|
return redisCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.bonus.sgzb.base.domain.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/11 15:55
|
||||||
|
* @Description iot绑定记录返回vo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IotRecordVo {
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "iot设备id")
|
||||||
|
private Long iotId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "绑定类型id")
|
||||||
|
private Long typeId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "绑定类型名称")
|
||||||
|
private String typeName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "设备编码")
|
||||||
|
private String maCode;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "绑定时间")
|
||||||
|
private String bindTime;
|
||||||
|
|
||||||
|
/** 解绑时间 */
|
||||||
|
@ApiModelProperty(value = "解绑时间")
|
||||||
|
private String unBindTime;
|
||||||
|
|
||||||
|
/** iot设备类型 */
|
||||||
|
@ApiModelProperty(value = "iot设备类型")
|
||||||
|
private String iotType;
|
||||||
|
|
||||||
|
/** iot设备类型名称 */
|
||||||
|
@ApiModelProperty(value = "iot设备类型名称")
|
||||||
|
private String iotTypeName;
|
||||||
|
|
||||||
|
/** iot设备编码 */
|
||||||
|
@ApiModelProperty(value = "iot设备编码")
|
||||||
|
private String iotCode;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.bonus.sgzb.base.mapper;
|
||||||
|
|
||||||
|
import com.bonus.sgzb.base.domain.vo.IotRecordVo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/4 16:28
|
||||||
|
* iot设备管理mapper层
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface IotMachineMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备类型
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotRecordVo> selectList(@Param("maCode") String maCode);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bonus.sgzb.base.mapper.IotMachineMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<select id="selectList" resultType="com.bonus.sgzb.base.domain.vo.IotRecordVo">
|
||||||
|
SELECT
|
||||||
|
im.iot_type,im.iot_code
|
||||||
|
FROM
|
||||||
|
iot_machine im
|
||||||
|
left join iot_machine_bind imb on im.id = imb.iot_id
|
||||||
|
WHERE
|
||||||
|
imb.ma_code = #{maCode}
|
||||||
|
AND im.bind_status='0'
|
||||||
|
AND imb.unbinder IS NULL
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.bonus.sgzb.material.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IotLocationVo {
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long iotId;
|
||||||
|
|
||||||
|
/** 经度 */
|
||||||
|
@ApiModelProperty(value = "经度")
|
||||||
|
private BigDecimal callon;
|
||||||
|
|
||||||
|
/** 经度 */
|
||||||
|
@ApiModelProperty(value = "纬度")
|
||||||
|
private BigDecimal callat;
|
||||||
|
|
||||||
|
/** 开始时间 */
|
||||||
|
@ApiModelProperty(value = "开始时间")
|
||||||
|
private String beginTime;
|
||||||
|
|
||||||
|
/** 结束时间 */
|
||||||
|
@ApiModelProperty(value = "结束时间")
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
|
/** 详细地址 */
|
||||||
|
@ApiModelProperty(value = "详细地址")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
|
||||||
|
/** 报警时间 */
|
||||||
|
@ApiModelProperty(value = "报警时间")
|
||||||
|
private String startAlarmTime;
|
||||||
|
|
||||||
|
/** 报警内容 */
|
||||||
|
@ApiModelProperty(value = "报警内容")
|
||||||
|
private String startAlarm;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue