forked from floraachy/xiuos_IoT
Merge branch 'master' of https://gitlink.org.cn/xuos/xiuos_IoT
This commit is contained in:
commit
5c413a345d
|
@ -181,6 +181,7 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>com.aiit.xiuos.XiuosApplication</mainClass>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
|
@ -189,6 +190,15 @@
|
|||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<fork>true</fork>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--mybatis自动生成代码插件-->
|
||||
<plugin>
|
||||
<groupId>org.mybatis.generator</groupId>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package com.aiit.xiuos.Utils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.aiit.xiuos.Utils;
|
||||
|
||||
import com.aiit.xiuos.mqtt.MqttConfiguration;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import okhttp3.Credentials;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
@Component
|
||||
public class EmqxApiUtil {
|
||||
@Autowired
|
||||
MqttConfiguration mqttConfiguration;
|
||||
|
||||
|
||||
public String getClientInfo(String clientId){
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(mqttConfiguration.getApiurl()+"/api/v5/clients/"+clientId)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", Credentials.basic(mqttConfiguration.getApikey(), mqttConfiguration.getSecretkey()))
|
||||
.build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
return response.body().string();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.aiit.xiuos.Utils;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.io.RandomAccessFile;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
|
@ -168,6 +169,7 @@ public class HexUtil {
|
|||
bit = bs[i] & 0x0f; // 低四位, 与操作 0000 1111
|
||||
sb.append(chars[bit]);
|
||||
sb.append(' ');//每个Byte之间空格分隔
|
||||
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.aiit.xiuos.Utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class OTAFileUtil {
|
||||
public static byte[] getFile(String fileName, int offset,int size) {
|
||||
byte[] buffer = new byte[size];
|
||||
File file = new File(System.getProperty("user.dir") + "/otafiles/" + fileName);
|
||||
byte[] chunk;
|
||||
RandomAccessFile randomAccessFile =null;
|
||||
try {
|
||||
randomAccessFile = new RandomAccessFile(file, "r");
|
||||
int bytesRead;
|
||||
randomAccessFile.seek(offset);
|
||||
if ((bytesRead = randomAccessFile.read(buffer)) != -1) {
|
||||
if (bytesRead < size) {
|
||||
chunk = new byte[bytesRead];
|
||||
System.arraycopy(buffer, 0, chunk, 0, bytesRead);
|
||||
} else {
|
||||
chunk = new byte[size];
|
||||
System.arraycopy(buffer, 0, chunk, 0, size);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if(randomAccessFile!=null){
|
||||
try{
|
||||
randomAccessFile.close();
|
||||
System.out.println("文件流关闭"+"offset="+offset);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String rgs[]) {
|
||||
|
||||
byte[] chunk = OTAFileUtil.getFile("2_ota_refresh.svg", 0,1024);
|
||||
System.out.println();
|
||||
String filePath = System.getProperty("user.dir") + "/otafiles/" + "2_ota_refresh.svg";
|
||||
|
||||
FileUtil.del(filePath);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,11 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
public class XiuosApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
SpringApplication.run(XiuosApplication.class, args);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ public class DeviceController {
|
|||
@GetMapping("/getRunStatusCount")
|
||||
public ResultRespons getRunStatusCount(HttpServletRequest request){
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
List<Map<String,String>> list=deviceInfoService.getDeviceRunStautsCount(userInfo.getOrg());
|
||||
List<Map<String,String>> list=deviceInfoService.getDeviceRunStatusCount(userInfo.getOrg());
|
||||
if(list!=null){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",list);
|
||||
}
|
||||
|
@ -97,9 +97,6 @@ public class DeviceController {
|
|||
@GetMapping("/updateDeviceStatus")
|
||||
public ResultRespons updateDeviceStatus(HttpServletRequest request){
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
if(userInfo==null){
|
||||
return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!");
|
||||
}
|
||||
List<DeviceInfo> list=deviceInfoService.selectActiveDevice(userInfo.getOrg());
|
||||
if(list!=null){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备成功!",list);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.aiit.xiuos.controller;
|
||||
|
||||
import com.aiit.xiuos.Utils.Constant;
|
||||
import com.aiit.xiuos.Utils.EmqxApiUtil;
|
||||
import com.aiit.xiuos.Utils.ResultRespons;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class EmqxApiController {
|
||||
@Autowired
|
||||
EmqxApiUtil emqxApiUtil;
|
||||
@GetMapping("/getClient")
|
||||
public ResultRespons selectDevice(@RequestParam("clientId") String clientId){
|
||||
String res= emqxApiUtil.getClientInfo(clientId);
|
||||
if(StringUtils.contains(res,"clientid")){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询设备状态成功");
|
||||
}else{
|
||||
return new ResultRespons(Constant.ERROR_CODE,"设备不在线!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -104,10 +104,8 @@ public class FirmwareController {
|
|||
String version = firmwareInfo.getFileVersion();
|
||||
String filePath = System.getProperty("user.dir") + "/otafiles/" + version+"_"+fileName;
|
||||
Boolean flag = FileUtil.del(filePath);
|
||||
|
||||
if (flag) {
|
||||
int res = firmwareInfoService.deleteFirmware(id);
|
||||
|
||||
if (1 == res) {
|
||||
otaInfoService.deleteOtaInfo(fileName,version);
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "删除成功");
|
||||
|
@ -116,7 +114,7 @@ public class FirmwareController {
|
|||
}
|
||||
|
||||
} else {
|
||||
return new ResultRespons(Constant.ERROR_CODE, "固件不存在");
|
||||
return new ResultRespons(Constant.ERROR_CODE, "删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package com.aiit.xiuos.controller;
|
||||
|
||||
import com.aiit.xiuos.Utils.Constant;
|
||||
import com.aiit.xiuos.Utils.ResultRespons;
|
||||
import com.aiit.xiuos.model.LoraDeviceInfo;
|
||||
import com.aiit.xiuos.model.UserInfo;
|
||||
import com.aiit.xiuos.service.LoraDeviceInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/loraDevice")
|
||||
public class LoraDeviceController {
|
||||
@Autowired
|
||||
LoraDeviceInfoService loraDeviceInfoService;
|
||||
@PostMapping("/add")
|
||||
public ResultRespons addInfo (@RequestBody LoraDeviceInfo loraDeviceInfo, HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
loraDeviceInfo.setOrg(userInfo.getOrg());
|
||||
int res = loraDeviceInfoService.addInfo(loraDeviceInfo);
|
||||
if(1==res){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"新增lora设备信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"新增lora设备信息失败!");
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResultRespons updateInfo (@RequestBody LoraDeviceInfo loraDeviceInfo) {
|
||||
int res = loraDeviceInfoService.updateInfo(loraDeviceInfo);
|
||||
if(res>=0){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"更新lora设备信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"更新lora设备信息失败!");
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResultRespons deleteInfo (@RequestBody LoraDeviceInfo loraDeviceInfo) {
|
||||
int res = loraDeviceInfoService.deleteInfo(loraDeviceInfo.getDevEui());
|
||||
if(1==res){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"删除lora设备信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"删除lora设备信息失败!");
|
||||
}
|
||||
|
||||
@GetMapping("/select")
|
||||
public ResultRespons getInfo (@RequestParam("gatewayid") String id,HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
List<LoraDeviceInfo> res =null;
|
||||
if(StringUtils.isEmpty(id)){
|
||||
res = loraDeviceInfoService.selectInfo(userInfo.getOrg());
|
||||
}else{
|
||||
res = loraDeviceInfoService.selectInfoByGateway(id,userInfo.getOrg());
|
||||
}
|
||||
|
||||
if(null!=res){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询lora设备信息成功!",res);
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"查询lora设备信息失败!");
|
||||
}
|
||||
|
||||
@GetMapping("/getStatus")
|
||||
public ResultRespons getStatus (HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
List<Map<String,String>> statusList = loraDeviceInfoService.getDeviceRunStatusCount(userInfo.getOrg());
|
||||
if(null!=statusList){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询lora设备信息成功!",statusList);
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"查询lora设备信息失败!");
|
||||
}
|
||||
|
||||
@PostMapping("/offline")
|
||||
public ResultRespons setDeviceOffLine (HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
int res = loraDeviceInfoService.setDeviceOffline(userInfo.getOrg());
|
||||
if(res>=0){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"更新lora设备信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"更新lora设备信息失败!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.aiit.xiuos.controller;
|
||||
|
||||
import com.aiit.xiuos.Utils.Constant;
|
||||
import com.aiit.xiuos.Utils.ResultRespons;
|
||||
import com.aiit.xiuos.model.LoraDeviceInfo;
|
||||
import com.aiit.xiuos.model.LoraGatewayInfo;
|
||||
import com.aiit.xiuos.model.UserInfo;
|
||||
import com.aiit.xiuos.service.LoraDeviceInfoService;
|
||||
import com.aiit.xiuos.service.LoraGatewayInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/loraGateway")
|
||||
public class LoraGatewayController {
|
||||
@Autowired
|
||||
LoraGatewayInfoService loraGatewayInfoService;
|
||||
@PostMapping("/add")
|
||||
public ResultRespons addInfo (@RequestBody LoraGatewayInfo loraGatewayInfo, HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
loraGatewayInfo.setOrg(userInfo.getOrg());
|
||||
int res = loraGatewayInfoService.addGatewayInfo(loraGatewayInfo);
|
||||
if(1==res){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"新增lora网关信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"新增lora网关信息失败!");
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResultRespons updateInfo (@RequestBody LoraGatewayInfo loraGatewayInfo) {
|
||||
int res = loraGatewayInfoService.updateGatewayInfo(loraGatewayInfo);
|
||||
if(res>=0){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"更新lora设备信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"更新lora设备信息失败!");
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ResultRespons deleteInfo (@RequestBody LoraGatewayInfo loraGatewayInfo) {
|
||||
int res = loraGatewayInfoService.deleteGatewayInfo(loraGatewayInfo.getGatewayid());
|
||||
if(1==res){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"删除lora网关设备信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"删除lora网关设备信息失败!");
|
||||
}
|
||||
|
||||
@GetMapping("/select")
|
||||
public ResultRespons getInfo (HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
List<LoraGatewayInfo> res = loraGatewayInfoService.selectGatewayInfo(userInfo.getOrg());
|
||||
if(null!=res){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询lora网关信息成功!",res);
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"查询lora网关信息失败!");
|
||||
}
|
||||
|
||||
@GetMapping("/getStatus")
|
||||
public ResultRespons getStatus (HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
List<Map<String,String>> statusList = loraGatewayInfoService.getGatewayRunStatusCount(userInfo.getOrg());
|
||||
if(null!=statusList){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"查询lora设备信息成功!",statusList);
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"查询lora设备信息失败!");
|
||||
}
|
||||
|
||||
@PostMapping("/offline")
|
||||
public ResultRespons setGatewayOffLine (HttpServletRequest request) {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
int res = loraGatewayInfoService.setGatewayOffline(userInfo.getOrg());
|
||||
if(res>=0){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"更新lora网关信息成功!");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"更新lora网关信息失败!");
|
||||
}
|
||||
}
|
|
@ -1,79 +1,105 @@
|
|||
package com.aiit.xiuos.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
import com.aiit.xiuos.Utils.Constant;
|
||||
import com.aiit.xiuos.Utils.ResultRespons;
|
||||
import com.aiit.xiuos.model.FirmwareInfo;
|
||||
import com.aiit.xiuos.model.OtaInfo;
|
||||
import com.aiit.xiuos.model.UserInfo;
|
||||
import com.aiit.xiuos.mqtt.MyMqttClient;
|
||||
import com.aiit.xiuos.service.FirmwareInfoService;
|
||||
import com.aiit.xiuos.service.OtaInfoService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/ota")
|
||||
@Slf4j
|
||||
public class OTAController {
|
||||
@Autowired
|
||||
private MyMqttClient myMqttClient;
|
||||
@Autowired
|
||||
OtaInfoService otaInfoService;
|
||||
@Autowired
|
||||
FirmwareInfoService firmwareInfoService;
|
||||
|
||||
/*
|
||||
上传接口
|
||||
*/
|
||||
//MultipartFile用于接受前端传过来的file对象
|
||||
@PostMapping("/upload")
|
||||
public ResultRespons upload(MultipartFile file) throws IOException {
|
||||
String md5 = SecureUtil.md5(file.getInputStream());
|
||||
System.out.println("文件的md5是:"+md5);
|
||||
String filename = file.getOriginalFilename();//获取文件的名称
|
||||
// String flag = IdUtil.fastSimpleUUID();//通过Hutool工具包的IdUtil类获取uuid作为前缀
|
||||
String rootFilePath = System.getProperty("user.dir") + "/otafiles/" + filename;
|
||||
FileUtil.writeBytes(file.getBytes(), rootFilePath);//使用Hutool工具包将我们接收到文件保存到rootFilePath中
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "上传成功", filename);
|
||||
@GetMapping("/getAll")
|
||||
public ResultRespons getAllJob(@RequestParam("fileName") String fileName,@RequestParam("fileVersion") String fileVersion,HttpServletRequest request) {
|
||||
UserInfo userInfo = (UserInfo) request.getSession().getAttribute("user");
|
||||
List<OtaInfo> otaInfos = otaInfoService.getALL(fileName,fileVersion ,userInfo.getOrg());
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "查询成功", otaInfos);
|
||||
}
|
||||
|
||||
@PostMapping("/overJob")
|
||||
public ResultRespons overJob(@RequestBody OtaInfo otaInfo) {
|
||||
otaInfo.setStatus(0);
|
||||
otaInfoService.updateOtaInfo(otaInfo);
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "更新成功");
|
||||
}
|
||||
|
||||
@PostMapping("/reTryJob")
|
||||
public ResultRespons reTryJob(@RequestBody OtaInfo otaInfo) {
|
||||
String clientId =otaInfo.getDeviceId();
|
||||
String version =otaInfo.getFileVersion();
|
||||
String fileName =otaInfo.getFileName();
|
||||
FirmwareInfo firmwareInfo= firmwareInfoService.getByNameAndVersion(fileName,version);
|
||||
String md5 = firmwareInfo.getFileMd5();
|
||||
long size = firmwareInfo.getFileSize();
|
||||
int id =firmwareInfo.getId();
|
||||
JSONObject payload =new JSONObject();
|
||||
payload.put("fileId",id);
|
||||
payload.put("version",version);
|
||||
payload.put("md5",md5);
|
||||
payload.put("fileSize",size);
|
||||
myMqttClient.publish("ota/"+clientId+"/update",payload.toJSONString());
|
||||
//状态置为进行中
|
||||
otaInfo.setStatus(2);
|
||||
otaInfoService.updateOtaInfo(otaInfo);
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "开始下发");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
下载接口
|
||||
*/
|
||||
@GetMapping("/download/{name}")
|
||||
public ResultRespons getFiles(@PathVariable String name, HttpServletResponse response) {
|
||||
OutputStream os;//新建一个输出流对象
|
||||
String basePath = System.getProperty("user.dir") + "/otafiles/"; //定义文件上传的根路径
|
||||
List<String> fileNames = FileUtil.listFileNames(basePath);//获取所有的文件名称
|
||||
String fileName = fileNames.stream().filter(filename -> filename.contains(name)).findAny().orElse("");//找到跟参数一致的文件
|
||||
try {
|
||||
if (StrUtil.isNotEmpty(fileName)) {
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
response.setContentType("application/octet-stream");
|
||||
byte[] bytes = FileUtil.readBytes(basePath + fileName);//通过文件的路径读取文件字节流
|
||||
os = response.getOutputStream();//通过response的输出流返回文件
|
||||
os.write(bytes);
|
||||
os.flush();
|
||||
os.close();
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "下载成功");
|
||||
|
||||
@PostMapping("/addJob")
|
||||
public ResultRespons addJob(@RequestBody OtaInfo otaInfo, HttpServletRequest request){
|
||||
OtaInfo lastOta = otaInfoService.getJobById(otaInfo.getDeviceId());
|
||||
if(lastOta!=null){
|
||||
return new ResultRespons(Constant.ERROR_CODE,"新增升级任务失败,存在进行中的任务,请检查!");
|
||||
}
|
||||
UserInfo userInfo = (UserInfo) request.getSession().getAttribute("user");
|
||||
otaInfo.setOrg(userInfo.getOrg());
|
||||
otaInfo.setCurrentProcess(0);
|
||||
//立即执行
|
||||
if(otaInfo.getUpdateType()==0){
|
||||
String clientId =otaInfo.getDeviceId();
|
||||
String version =otaInfo.getFileVersion();
|
||||
String fileName =otaInfo.getFileName();
|
||||
FirmwareInfo firmwareInfo= firmwareInfoService.getByNameAndVersion(fileName,version);
|
||||
String md5 = firmwareInfo.getFileMd5();
|
||||
long size = firmwareInfo.getFileSize();
|
||||
int id =firmwareInfo.getId();
|
||||
JSONObject payload =new JSONObject();
|
||||
payload.put("fileId",id);
|
||||
payload.put("version",version);
|
||||
payload.put("md5",md5);
|
||||
payload.put("fileSize",size);
|
||||
myMqttClient.publish(1,false,"ota/"+clientId+"/update",payload.toJSONString());
|
||||
//状态置为进行中
|
||||
otaInfo.setStatus(2);
|
||||
}else{
|
||||
return new ResultRespons(Constant.ERROR_CODE, "文件名不存在");
|
||||
//状态设置未开始
|
||||
otaInfo.setStatus(3);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return new ResultRespons(Constant.ERROR_CODE, "下载失败");
|
||||
int res = otaInfoService.addOtaInfo(otaInfo);
|
||||
if(1==res){
|
||||
return new ResultRespons(Constant.SUCCESS_CODE,"新增升级任务成功");
|
||||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE,"新增升级任务失败");
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{name}")
|
||||
public ResultRespons deleteFile(@PathVariable String name) throws IOException {
|
||||
String filePath =System.getProperty("user.dir") + "/otafiles/"+name;
|
||||
Boolean flag =FileUtil.isFile(filePath);
|
||||
if(flag){
|
||||
FileUtil.del(filePath);
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "删除成功");
|
||||
}else{
|
||||
return new ResultRespons(Constant.ERROR_CODE, "文件不存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,12 @@ import com.aiit.xiuos.model.DeviceInfo;
|
|||
import com.aiit.xiuos.model.ProtocolProductInfo;
|
||||
import com.aiit.xiuos.model.UserInfo;
|
||||
import com.aiit.xiuos.model.VO.ProtocolProductVo;
|
||||
import com.aiit.xiuos.mqtt.MqttConfiguration;
|
||||
import com.aiit.xiuos.mqtt.MyMqttClient;
|
||||
import com.aiit.xiuos.service.DeviceInfoService;
|
||||
import com.aiit.xiuos.service.ProtocolService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -27,13 +30,12 @@ import java.util.Map;
|
|||
public class ProtocolProductInfoController {
|
||||
@Autowired
|
||||
private ProtocolService protocolService;
|
||||
@Autowired
|
||||
MyMqttClient myMqttClient;
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResultRespons addProtocolProduct(@RequestBody ProtocolProductVo protocolProductVo, HttpServletRequest request) throws ParseException {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
if(userInfo==null){
|
||||
return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!");
|
||||
}
|
||||
ProtocolProductInfo productInfo = protocolService.getProtocolByName(protocolProductVo.getProductName());
|
||||
|
||||
if (productInfo != null) {
|
||||
|
@ -62,9 +64,6 @@ public class ProtocolProductInfoController {
|
|||
@GetMapping("/selectAll")
|
||||
public ResultRespons selectProtocolProductList(HttpServletRequest request) throws ParseException {
|
||||
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
|
||||
if(userInfo==null){
|
||||
return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!");
|
||||
}
|
||||
List<ProtocolProductInfo> protocolProductInfos = protocolService.getProtocolAll(userInfo.getOrg());
|
||||
List<ProtocolProductVo> protocolProductVos= new ArrayList<>();
|
||||
if (protocolProductInfos != null && protocolProductInfos.size() >= 0) {
|
||||
|
@ -119,4 +118,13 @@ public class ProtocolProductInfoController {
|
|||
}
|
||||
return new ResultRespons(Constant.ERROR_CODE, "导出csv成功!");
|
||||
}
|
||||
|
||||
@PostMapping("/publish")
|
||||
public ResultRespons publish(@RequestBody Map<String, Object> jsonMap) {
|
||||
String clientId =jsonMap.get("clientId").toString();
|
||||
String jsonString =jsonMap.get("jsonString").toString();
|
||||
log.info("发送的配方消息是:"+jsonString);
|
||||
myMqttClient.publish("protocol/"+clientId+"/files",jsonString);
|
||||
return new ResultRespons(Constant.SUCCESS_CODE, "协议已推送!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ public interface FirmwareInfoMapper {
|
|||
|
||||
int updateByPrimaryKey(FirmwareInfo record);
|
||||
|
||||
@Select("select * from firmware_info where org=#{org}")
|
||||
@Select("select * from firmware_info where org=#{org} order by id desc")
|
||||
List<FirmwareInfo> getAll(@Param("org") String org);
|
||||
|
||||
@Select("select * from firmware_info where org=#{org} and verify=#{verify}")
|
||||
@Select("select * from firmware_info where org=#{org} and verify=#{verify} order by id desc")
|
||||
List<FirmwareInfo> getByVerify(@Param("org") String org,@Param("verify") String verify);
|
||||
|
||||
@Select("select * from firmware_info where file_name=#{name}")
|
||||
@Select("select * from firmware_info where file_name=#{name} order by id desc")
|
||||
List<FirmwareInfo> getByName(@Param("name") String name);
|
||||
|
||||
@Select("select * from firmware_info where file_name=#{name} and file_version=#{version} ")
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.aiit.xiuos.dao.mappers;
|
||||
|
||||
import com.aiit.xiuos.model.LoraDeviceInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public interface LoraDeviceInfoMapper {
|
||||
int deleteByPrimaryKey(String deveui);
|
||||
|
||||
int insert(LoraDeviceInfo record);
|
||||
|
||||
int insertSelective(LoraDeviceInfo record);
|
||||
|
||||
LoraDeviceInfo selectByPrimaryKey(String deveui);
|
||||
|
||||
int updateByPrimaryKeySelective(LoraDeviceInfo record);
|
||||
|
||||
int updateByPrimaryKey(LoraDeviceInfo record);
|
||||
|
||||
@Select("select * from lora_device_info where org=#{org}")
|
||||
List<LoraDeviceInfo> selectAll(@Param("org") String org);
|
||||
|
||||
@Select("select * from lora_device_info where gatewayId=#{id} and org=#{org}")
|
||||
List<LoraDeviceInfo> selectById(@Param("id") String id,@Param("org") String org);
|
||||
|
||||
|
||||
@Select("select d.status ,count(d.status) from lora_device_info d where org = #{org} GROUP BY d.status")
|
||||
List<Map<String,String>> getDeviceRunStatusCount(@Param("org") String org);
|
||||
|
||||
@Update("update lora_device_info set status= 2 where status = 1 and org = #{org} ")
|
||||
int setDeviceOffLine(@Param("org") String org);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.aiit.xiuos.dao.mappers;
|
||||
|
||||
import com.aiit.xiuos.model.LoraDeviceInfo;
|
||||
import com.aiit.xiuos.model.LoraGatewayInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public interface LoraGatewayInfoMapper {
|
||||
int deleteByPrimaryKey(String gatewayid);
|
||||
|
||||
int insert(LoraGatewayInfo record);
|
||||
|
||||
int insertSelective(LoraGatewayInfo record);
|
||||
|
||||
LoraGatewayInfo selectByPrimaryKey(String gatewayid);
|
||||
|
||||
int updateByPrimaryKeySelective(LoraGatewayInfo record);
|
||||
|
||||
int updateByPrimaryKey(LoraGatewayInfo record);
|
||||
|
||||
@Select("select * from lora_gateway_info where org=#{org}")
|
||||
List<LoraGatewayInfo> selectAll(@Param("org") String org);
|
||||
|
||||
@Select("select d.status ,count(d.status) from lora_gateway_info d where org = #{org} GROUP BY d.status")
|
||||
List<Map<String,String>> getGatewayRunStatusCount(@Param("org") String org);
|
||||
|
||||
@Update("update lora_gateway_info set status= 2 where status = 1 and org = #{org} ")
|
||||
int setGatewayOffLine(@Param("org") String org);
|
||||
}
|
|
@ -1,7 +1,14 @@
|
|||
package com.aiit.xiuos.dao.mappers;
|
||||
|
||||
import com.aiit.xiuos.model.FirmwareInfo;
|
||||
import com.aiit.xiuos.model.OtaInfo;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
@Repository
|
||||
public interface OtaInfoMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
|
@ -14,4 +21,16 @@ public interface OtaInfoMapper {
|
|||
int updateByPrimaryKeySelective(OtaInfo record);
|
||||
|
||||
int updateByPrimaryKey(OtaInfo record);
|
||||
|
||||
@Select("select * from ota_info where file_name=#{name} and file_version =#{version} and org=#{org} order by create_time desc")
|
||||
List<OtaInfo> getAll(@Param("name") String name,@Param("version") String version,@Param("org") String org);
|
||||
|
||||
@Select("select * from ota_info where update_type=1 and status =3")
|
||||
List<OtaInfo> getJob();
|
||||
|
||||
@Select("select * from ota_info where device_id =#{device_id} and status =2")
|
||||
OtaInfo getOtaInfo(@Param("device_id") String deviceId);
|
||||
|
||||
@Delete("delete from ota_info where file_name=#{name} and file_version =#{version}")
|
||||
int deleteOtaInfo(@Param("name") String name,@Param("version") String version);
|
||||
}
|
|
@ -6,10 +6,10 @@ import lombok.Data;
|
|||
@Data
|
||||
@Builder
|
||||
public class DeviceInfo {
|
||||
private String id;
|
||||
|
||||
private String no;
|
||||
|
||||
private String id;
|
||||
|
||||
private String productname;
|
||||
|
||||
private String type;
|
||||
|
@ -56,9 +56,9 @@ public class DeviceInfo {
|
|||
|
||||
private String org;
|
||||
|
||||
public DeviceInfo(String id, String no, String productname, String type, Integer activestatus, String updatetime, String devicedesc, Integer runstatus, String statusdesc, String kernel, String webversion, String ipaddr, String netmask, String gateway, String dnsserver0, String dnsserver1, String topic, String serveraddr, String serverport, String username, String clientid, String privateserveraddr, String privateserverport, String privateserverusername, String org) {
|
||||
this.id = id;
|
||||
public DeviceInfo(String no, String id, String productname, String type, Integer activestatus, String updatetime, String devicedesc, Integer runstatus, String statusdesc, String kernel, String webversion, String ipaddr, String netmask, String gateway, String dnsserver0, String dnsserver1, String topic, String serveraddr, String serverport, String username, String clientid, String privateserveraddr, String privateserverport, String privateserverusername, String org) {
|
||||
this.no = no;
|
||||
this.id = id;
|
||||
this.productname = productname;
|
||||
this.type = type;
|
||||
this.activestatus = activestatus;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package com.aiit.xiuos.model;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class LoraDeviceInfo {
|
||||
private String devEui;
|
||||
|
||||
private String joinEui;
|
||||
|
||||
private String name;
|
||||
|
||||
private String appKey;
|
||||
|
||||
private Boolean supportOtaa;
|
||||
|
||||
private Boolean supportClassc;
|
||||
|
||||
private String gatewayid;
|
||||
|
||||
private String remark1;
|
||||
|
||||
private String remark2;
|
||||
|
||||
private String org;
|
||||
|
||||
private String remark3;
|
||||
|
||||
private String remark4;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String remark5;
|
||||
|
||||
public LoraDeviceInfo(String devEui, String joinEui, String name, String appKey, Boolean supportOtaa, Boolean supportClassc, String gatewayid, String remark1, String remark2, String org, String remark3, String remark4, Integer status, String remark5) {
|
||||
this.devEui = devEui;
|
||||
this.joinEui = joinEui;
|
||||
this.name = name;
|
||||
this.appKey = appKey;
|
||||
this.supportOtaa = supportOtaa;
|
||||
this.supportClassc = supportClassc;
|
||||
this.gatewayid = gatewayid;
|
||||
this.remark1 = remark1;
|
||||
this.remark2 = remark2;
|
||||
this.org = org;
|
||||
this.remark3 = remark3;
|
||||
this.remark4 = remark4;
|
||||
this.status = status;
|
||||
this.remark5 = remark5;
|
||||
}
|
||||
|
||||
public LoraDeviceInfo() {
|
||||
super();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.aiit.xiuos.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class LoraGatewayInfo {
|
||||
private String gatewayid;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer deviceNum;
|
||||
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||
private Date lastConnect;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private String org;
|
||||
|
||||
private String remark1;
|
||||
|
||||
private String remark2;
|
||||
|
||||
private String remark3;
|
||||
|
||||
private String remark4;
|
||||
|
||||
private String remark5;
|
||||
|
||||
public LoraGatewayInfo(String gatewayid, String name, Integer deviceNum, Date lastConnect, Integer status, String org, String remark1, String remark2, String remark3, String remark4, String remark5) {
|
||||
this.gatewayid = gatewayid;
|
||||
this.name = name;
|
||||
this.deviceNum = deviceNum;
|
||||
this.lastConnect = lastConnect;
|
||||
this.status = status;
|
||||
this.org = org;
|
||||
this.remark1 = remark1;
|
||||
this.remark2 = remark2;
|
||||
this.remark3 = remark3;
|
||||
this.remark4 = remark4;
|
||||
this.remark5 = remark5;
|
||||
}
|
||||
|
||||
public LoraGatewayInfo() {
|
||||
super();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package com.aiit.xiuos.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -16,7 +18,7 @@ public class OtaInfo {
|
|||
private Integer currentProcess;
|
||||
|
||||
private Integer status;
|
||||
|
||||
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
private Integer updateType;
|
||||
|
@ -25,7 +27,9 @@ public class OtaInfo {
|
|||
|
||||
private String fileVersion;
|
||||
|
||||
public OtaInfo(Integer id, String fileName, String deviceId, Integer currentProcess, Integer status, Date createTime, Integer updateType, Date timeout, String fileVersion) {
|
||||
private String org;
|
||||
|
||||
public OtaInfo(Integer id, String fileName, String deviceId, Integer currentProcess, Integer status, Date createTime, Integer updateType, Date timeout, String fileVersion, String org) {
|
||||
this.id = id;
|
||||
this.fileName = fileName;
|
||||
this.deviceId = deviceId;
|
||||
|
@ -35,6 +39,7 @@ public class OtaInfo {
|
|||
this.updateType = updateType;
|
||||
this.timeout = timeout;
|
||||
this.fileVersion = fileVersion;
|
||||
this.org = org;
|
||||
}
|
||||
|
||||
public OtaInfo() {
|
||||
|
|
|
@ -3,20 +3,16 @@ package com.aiit.xiuos.mqtt;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties("mqtt")
|
||||
@Setter
|
||||
@Getter
|
||||
@Slf4j
|
||||
public class MqttConfiguration {
|
||||
@Autowired
|
||||
private MyMqttClient myMqttClient;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
|
@ -47,12 +43,19 @@ public class MqttConfiguration {
|
|||
*/
|
||||
private int keepalive;
|
||||
|
||||
private String apikey;
|
||||
private String secretkey;
|
||||
private String apiurl;
|
||||
|
||||
@Bean
|
||||
public MyMqttClient getMqttPushClient() {
|
||||
MyMqttClient myMqttClient =new MyMqttClient();
|
||||
myMqttClient.connect(hostUrl, clientId, username, password, timeout, keepalive);
|
||||
// 以/#结尾表示订阅所有以test开头的主题
|
||||
myMqttClient.subscribe(defaultTopic, 0);
|
||||
log.info("订阅成功"+defaultTopic);
|
||||
myMqttClient.subscribe("$SYS/brokers/+/clients/+/#", 1);
|
||||
log.info("订阅成功,clientId:"+clientId);
|
||||
return myMqttClient;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,112 @@
|
|||
package com.aiit.xiuos.mqtt;
|
||||
|
||||
import com.aiit.xiuos.Utils.MyUtils;
|
||||
import com.aiit.xiuos.Utils.OTAFileUtil;
|
||||
import com.aiit.xiuos.Utils.SpringUtil;
|
||||
import com.aiit.xiuos.model.DeviceInfo;
|
||||
import com.aiit.xiuos.model.FirmwareInfo;
|
||||
import com.aiit.xiuos.model.OtaInfo;
|
||||
import com.aiit.xiuos.service.DeviceInfoService;
|
||||
import com.aiit.xiuos.service.FirmwareInfoService;
|
||||
import com.aiit.xiuos.service.OtaInfoService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
public class MsgReceiveHandle {
|
||||
|
||||
private OtaInfoService otaInfoService=SpringUtil.getBeanByClass(OtaInfoService.class);
|
||||
|
||||
private FirmwareInfoService firmwareInfoService=SpringUtil.getBeanByClass(FirmwareInfoService.class);
|
||||
|
||||
private DeviceInfoService deviceInfoService=SpringUtil.getBeanByClass(DeviceInfoService.class);
|
||||
|
||||
|
||||
private MyMqttClient myMqttClient= SpringUtil.getBeanByClass(MyMqttClient.class);
|
||||
|
||||
public void handleConnected(JSONObject msgJson) {
|
||||
String deviceId =msgJson.getString("clientid");
|
||||
System.out.println("收到设备上线信息,设备ID:" + msgJson.getString("clientid"));
|
||||
DeviceInfo deviceInfo = deviceInfoService.selectbyNo(deviceId);
|
||||
if(deviceInfo==null){
|
||||
log.info("平台不存在该设备id,请检查");
|
||||
return;
|
||||
}
|
||||
deviceInfo.setUpdatetime(MyUtils.getTime());
|
||||
deviceInfo.setActivestatus(1);
|
||||
deviceInfoService.updateDeviceInfo(deviceInfo);
|
||||
}
|
||||
|
||||
public void handleDisConnected(JSONObject msgJson) {
|
||||
String deviceId =msgJson.getString("clientid");
|
||||
System.out.println("收到设备下线信息,设备ID:" + msgJson.getString("clientid"));
|
||||
DeviceInfo deviceInfo = deviceInfoService.selectbyNo(deviceId);
|
||||
if(deviceInfo==null){
|
||||
log.info("平台不存在该设备id,请检查");
|
||||
return;
|
||||
}
|
||||
deviceInfo.setUpdatetime(MyUtils.getTime());
|
||||
deviceInfo.setActivestatus(0);
|
||||
deviceInfoService.updateDeviceInfo(deviceInfo);
|
||||
}
|
||||
|
||||
public void handleOtaFile(JSONObject msgJson) {
|
||||
int fileId = msgJson.getIntValue("fileId");
|
||||
int fileOffset = msgJson.getIntValue("fileOffset");
|
||||
int size = msgJson.getIntValue("size");
|
||||
String clientId = msgJson.getString("clientId");
|
||||
OtaInfo otaInfo = otaInfoService.getJobById(clientId);
|
||||
if(otaInfo!=null){
|
||||
otaInfo.setCurrentProcess(fileOffset+size);
|
||||
otaInfoService.updateOtaInfo(otaInfo);
|
||||
}
|
||||
FirmwareInfo firmwareInfo = firmwareInfoService.getById(fileId);
|
||||
String version =firmwareInfo.getFileVersion();
|
||||
String name = firmwareInfo.getFileName();
|
||||
String realName = version+"_"+name;
|
||||
byte[] chunk = OTAFileUtil.getFile(realName, fileOffset,size);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("file",chunk);
|
||||
myMqttClient.publish(1,false,"ota/" + clientId + "/files", chunk);
|
||||
}
|
||||
|
||||
public void handleOtaVersion(JSONObject msgJson) {
|
||||
String deviceId = msgJson.getString("clientId");
|
||||
String version = msgJson.getString("version");
|
||||
DeviceInfo deviceInfo = deviceInfoService.selectbyNo(deviceId);
|
||||
if(deviceInfo==null) {
|
||||
log.info("不存在设备号为" + deviceId + "的设备");
|
||||
return;
|
||||
}
|
||||
deviceInfo.setUpdatetime(MyUtils.getTime());
|
||||
deviceInfo.setWebversion(version);
|
||||
//查看是否存在进行中的ota信息
|
||||
OtaInfo otaInfo = otaInfoService.getJobById(deviceId);
|
||||
if(otaInfo!=null){
|
||||
String targetVersion = otaInfo.getFileVersion();
|
||||
if(version.equals(targetVersion)){
|
||||
otaInfo.setStatus(1);
|
||||
|
||||
}else {
|
||||
otaInfo.setStatus(0);
|
||||
}
|
||||
otaInfoService.updateOtaInfo(otaInfo);
|
||||
}
|
||||
deviceInfoService.updateDeviceInfo(deviceInfo);
|
||||
|
||||
|
||||
System.out.println("更新设备" + deviceId + "版本为" + version);
|
||||
//执行更新内核版本操作,并更新ota状态为失败。
|
||||
}
|
||||
|
||||
public void handleClientData(JSONObject msgJson) {
|
||||
String clientId = msgJson.getString("clientId");
|
||||
JSONObject data =msgJson.getJSONObject("data");
|
||||
String time =msgJson.getString("time");
|
||||
System.out.println("收到设备" + clientId + "的数据" + data.toJSONString());
|
||||
//执行更新内核版本操作,并更新ota状态为失败。
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,20 @@ package com.aiit.xiuos.mqtt;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author wangtianyi
|
||||
* @description mqtt客户端
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MyMqttClient {
|
||||
|
||||
|
||||
@Autowired
|
||||
PushCallback pushCallback;
|
||||
|
||||
private static MqttClient client;
|
||||
|
||||
|
@ -88,13 +91,37 @@ public class MyMqttClient {
|
|||
message.setRetained(retained);
|
||||
message.setPayload(pushMessage.getBytes());
|
||||
MqttTopic mqttTopic= MyMqttClient.getClient().getTopic(topic);
|
||||
|
||||
if(null== mqttTopic){
|
||||
log.error("topic not exist");
|
||||
}
|
||||
MqttDeliveryToken token;
|
||||
try {
|
||||
//client.publish(topic,message);
|
||||
token=mqttTopic.publish(message);
|
||||
token.waitForCompletion();
|
||||
token.waitForCompletion(100);
|
||||
}catch (MqttPersistenceException e){
|
||||
log.error(e.getMessage());
|
||||
}catch (MqttException e){
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void publish(int qos,boolean retained,String topic,byte[] payload){
|
||||
MqttMessage message=new MqttMessage();
|
||||
message.setQos(qos);
|
||||
message.setRetained(retained);
|
||||
message.setPayload(payload);
|
||||
MqttTopic mqttTopic= MyMqttClient.getClient().getTopic(topic);
|
||||
|
||||
if(null== mqttTopic){
|
||||
log.error("topic not exist");
|
||||
}
|
||||
MqttDeliveryToken token;
|
||||
try {
|
||||
//client.publish(topic,message);
|
||||
token=mqttTopic.publish(message);
|
||||
token.waitForCompletion(100);
|
||||
}catch (MqttPersistenceException e){
|
||||
log.error(e.getMessage());
|
||||
}catch (MqttException e){
|
||||
|
@ -107,13 +134,14 @@ public class MyMqttClient {
|
|||
* @param topic
|
||||
*/
|
||||
public void subscribe(String topic){
|
||||
log.error("开始订阅主题" + topic);
|
||||
log.info("开始订阅主题" + topic);
|
||||
subscribe(topic,0);
|
||||
}
|
||||
|
||||
public void subscribe(String topic,int qos){
|
||||
try {
|
||||
MyMqttClient.getClient().subscribe(topic,qos);
|
||||
log.info("开始订阅主题" + topic);
|
||||
}catch (MqttException e){
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
|
|
@ -1,22 +1,30 @@
|
|||
package com.aiit.xiuos.mqtt;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.aiit.xiuos.Utils.SpringUtil;
|
||||
import com.aiit.xiuos.service.OtaInfoService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PushCallback implements MqttCallbackExtended {
|
||||
|
||||
|
||||
@Autowired
|
||||
private MyMqttClient myMqttClient;
|
||||
|
||||
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
log.error("mqtt lose connect:"+throwable) ;
|
||||
log.error("mqtt lose connect") ;
|
||||
throwable.printStackTrace();
|
||||
long reconnectTimes = 1;
|
||||
while (true) {
|
||||
try {
|
||||
|
@ -28,6 +36,7 @@ public class PushCallback implements MqttCallbackExtended {
|
|||
myMqttClient.getClient().reconnect();
|
||||
} catch (MqttException e) {
|
||||
log.error("", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
|
@ -38,11 +47,33 @@ public class PushCallback implements MqttCallbackExtended {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||
public void messageArrived(String topic, MqttMessage message) {
|
||||
MsgReceiveHandle msgReceiveHandle = new MsgReceiveHandle();
|
||||
System.out.println("接收消息主题 : " + topic);
|
||||
System.out.println("接收消息Qos : " + message.getQos());
|
||||
System.out.println("接收消息内容 : " + new String(message.getPayload()));
|
||||
String msg = new String(message.getPayload());
|
||||
System.out.println("接收消息内容 : " + msg);
|
||||
|
||||
try{
|
||||
JSONObject jsonObject = JSON.parseObject(msg);
|
||||
if (topic.endsWith("disconnected")) {
|
||||
msgReceiveHandle.handleDisConnected(jsonObject);
|
||||
} else if(topic.endsWith("connected")){
|
||||
msgReceiveHandle.handleConnected(jsonObject);
|
||||
} else if(topic.endsWith("ota/files")){
|
||||
msgReceiveHandle.handleOtaFile(jsonObject);
|
||||
} else if(topic.endsWith("ota/version")){
|
||||
msgReceiveHandle.handleOtaVersion(jsonObject);
|
||||
} else if(topic.endsWith("/data")){
|
||||
msgReceiveHandle.handleClientData(jsonObject);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("处理信息发生错误,请检查");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||
|
|
|
@ -34,7 +34,7 @@ public class GZJCTaskScheduled {
|
|||
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 */1 * * * ?")//every hour
|
||||
@Scheduled(cron = "0 */1 * * * ?")//every minute
|
||||
public void sendWebsocket() throws ParseException, IOException {
|
||||
GZJCData GZJCData = mockData();
|
||||
JSONObject jsonObject = JSONUtil.parseObj(GZJCData,false,true);
|
||||
|
|
|
@ -1,4 +1,47 @@
|
|||
package com.aiit.xiuos.scheduled;
|
||||
|
||||
import com.aiit.xiuos.model.FirmwareInfo;
|
||||
import com.aiit.xiuos.model.OtaInfo;
|
||||
import com.aiit.xiuos.mqtt.MyMqttClient;
|
||||
import com.aiit.xiuos.service.FirmwareInfoService;
|
||||
import com.aiit.xiuos.service.OtaInfoService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import netscape.javascript.JSObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OTATaskScheduled {
|
||||
@Autowired
|
||||
MyMqttClient myMqttClient;
|
||||
@Autowired
|
||||
FirmwareInfoService firmwareInfoService;
|
||||
@Autowired
|
||||
OtaInfoService otaInfoService;
|
||||
@Scheduled(cron = "0 0 0 * * ?")//每日凌晨
|
||||
public void startOta(){
|
||||
List<OtaInfo> lists = otaInfoService.getNightJob();
|
||||
for(int i=0;i<lists.size();i++){
|
||||
OtaInfo otaInfo = lists.get(i);
|
||||
String fileName =otaInfo.getFileName();
|
||||
String version = otaInfo.getFileVersion();
|
||||
FirmwareInfo firmwareInfo =firmwareInfoService.getByNameAndVersion(fileName,version);
|
||||
String md5 = firmwareInfo.getFileMd5();
|
||||
long size =firmwareInfo.getFileSize();
|
||||
String clientId =otaInfo.getDeviceId();
|
||||
JSONObject payload =new JSONObject();
|
||||
payload.put("fileName",fileName);
|
||||
payload.put("version",version);
|
||||
payload.put("md5",md5);
|
||||
payload.put("fileSize",size);
|
||||
myMqttClient.publish("ota/"+clientId+"/update",payload.toJSONString());
|
||||
otaInfo.setStatus(2);
|
||||
otaInfoService.updateOtaInfo(otaInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,11 @@ public interface DeviceInfoService {
|
|||
int activeDeviceByNo(String no);
|
||||
List<DeviceInfo> selectActiveDevice(String org);
|
||||
List<DeviceInfo> selectUnActiveDevice(String org);
|
||||
List<DeviceInfo> selectbyNo(String no);
|
||||
DeviceInfo selectbyNo(String no);
|
||||
List<Map<String,String>> getDeviceTypeCount(String org);
|
||||
List<Map<String,String>> getDeviceRunStautsCount(String org);
|
||||
List<Map<String,String>> getDeviceRunStatusCount(String org);
|
||||
String getTypeByName(String deviceNo);
|
||||
List<String> getDeviceList(String org);
|
||||
int updateDeviceInfo(DeviceInfo deviceInfo);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.aiit.xiuos.service;
|
||||
|
||||
import com.aiit.xiuos.model.LoraDeviceInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface LoraDeviceInfoService {
|
||||
int addInfo (LoraDeviceInfo loraDeviceInfo);
|
||||
int updateInfo(LoraDeviceInfo loraDeviceInfo);
|
||||
int deleteInfo (String deveui);
|
||||
List<LoraDeviceInfo> selectInfo(String org);
|
||||
List<LoraDeviceInfo> selectInfoByGateway(String id,String org);
|
||||
List<Map<String,String>> getDeviceRunStatusCount(String org);
|
||||
int setDeviceOffline (String org);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.aiit.xiuos.service;
|
||||
|
||||
import com.aiit.xiuos.model.LoraGatewayInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface LoraGatewayInfoService {
|
||||
int addGatewayInfo(LoraGatewayInfo loraGatewayInfo);
|
||||
int updateGatewayInfo(LoraGatewayInfo loraGatewayInfo);
|
||||
List<LoraGatewayInfo> selectGatewayInfo(String org);
|
||||
int deleteGatewayInfo(String gatewayId);
|
||||
List<Map<String,String>> getGatewayRunStatusCount(String org);
|
||||
int setGatewayOffline (String org);
|
||||
}
|
|
@ -1,4 +1,16 @@
|
|||
package com.aiit.xiuos.service;
|
||||
|
||||
import com.aiit.xiuos.model.OtaInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface OtaInfoService {
|
||||
List<OtaInfo> getALL(String name,String version ,String org);
|
||||
int addOtaInfo(OtaInfo info);
|
||||
List<OtaInfo> getNightJob();
|
||||
int updateOtaInfo(OtaInfo info);
|
||||
OtaInfo getJobById(String clientId);
|
||||
int deleteOtaInfo(String name,String version);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceInfo> selectbyNo(String no) {
|
||||
return deviceInfoMapper.selectByNo(no);
|
||||
public DeviceInfo selectbyNo(String no) {
|
||||
return deviceInfoMapper.selectByPrimaryKey(no);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +52,7 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, String>> getDeviceRunStautsCount(String org) {
|
||||
public List<Map<String, String>> getDeviceRunStatusCount(String org) {
|
||||
return deviceInfoMapper.getDeviceRunStatusCount(org);
|
||||
}
|
||||
|
||||
|
@ -64,4 +64,14 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDeviceList(String org) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateDeviceInfo(DeviceInfo deviceInfo) {
|
||||
return deviceInfoMapper.updateByPrimaryKeySelective(deviceInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.aiit.xiuos.service.impl;
|
||||
|
||||
import com.aiit.xiuos.dao.mappers.LoraDeviceInfoMapper;
|
||||
import com.aiit.xiuos.model.LoraDeviceInfo;
|
||||
import com.aiit.xiuos.service.LoraDeviceInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class LoraDeviceInfoServiceImpl implements LoraDeviceInfoService {
|
||||
@Autowired
|
||||
LoraDeviceInfoMapper loraDeviceInfoMapper;
|
||||
|
||||
@Override
|
||||
public int addInfo(LoraDeviceInfo loraDeviceInfo) {
|
||||
return loraDeviceInfoMapper.insert(loraDeviceInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateInfo(LoraDeviceInfo loraDeviceInfo) {
|
||||
return loraDeviceInfoMapper.updateByPrimaryKeySelective(loraDeviceInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteInfo(String deveui) {
|
||||
return loraDeviceInfoMapper.deleteByPrimaryKey(deveui);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LoraDeviceInfo> selectInfo(String org) {
|
||||
return loraDeviceInfoMapper.selectAll(org);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LoraDeviceInfo> selectInfoByGateway(String id, String org) {
|
||||
return loraDeviceInfoMapper.selectById(id,org);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String,String>> getDeviceRunStatusCount(String org) {
|
||||
return loraDeviceInfoMapper.getDeviceRunStatusCount(org);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setDeviceOffline(String org) {
|
||||
return loraDeviceInfoMapper.setDeviceOffLine(org);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.aiit.xiuos.service.impl;
|
||||
|
||||
import com.aiit.xiuos.dao.mappers.LoraDeviceInfoMapper;
|
||||
import com.aiit.xiuos.dao.mappers.LoraGatewayInfoMapper;
|
||||
import com.aiit.xiuos.model.LoraGatewayInfo;
|
||||
import com.aiit.xiuos.service.LoraGatewayInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class LoraGatewayInfoServiceImpl implements LoraGatewayInfoService {
|
||||
@Autowired
|
||||
LoraGatewayInfoMapper loraGatewayInfoMapper;
|
||||
@Override
|
||||
public int addGatewayInfo(LoraGatewayInfo loraGatewayInfo) {
|
||||
return loraGatewayInfoMapper.insert(loraGatewayInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateGatewayInfo(LoraGatewayInfo loraGatewayInfo) {
|
||||
return loraGatewayInfoMapper.updateByPrimaryKeySelective(loraGatewayInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LoraGatewayInfo> selectGatewayInfo(String org) {
|
||||
return loraGatewayInfoMapper.selectAll(org);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteGatewayInfo(String gatewayId) {
|
||||
return loraGatewayInfoMapper.deleteByPrimaryKey(gatewayId);
|
||||
}
|
||||
@Override
|
||||
public List<Map<String,String>> getGatewayRunStatusCount(String org) {
|
||||
return loraGatewayInfoMapper.getGatewayRunStatusCount(org);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setGatewayOffline(String org) {
|
||||
return loraGatewayInfoMapper.setGatewayOffLine(org);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,43 @@
|
|||
package com.aiit.xiuos.service.impl;
|
||||
|
||||
public class OtaInfoServiceImpl {
|
||||
import com.aiit.xiuos.dao.mappers.OtaInfoMapper;
|
||||
import com.aiit.xiuos.model.OtaInfo;
|
||||
import com.aiit.xiuos.service.OtaInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@Service
|
||||
public class OtaInfoServiceImpl implements OtaInfoService {
|
||||
@Autowired
|
||||
OtaInfoMapper otaInfoMapper;
|
||||
@Override
|
||||
public List<OtaInfo> getALL(String name,String version,String org) {
|
||||
return otaInfoMapper.getAll(name,version,org);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addOtaInfo(OtaInfo info) {
|
||||
return otaInfoMapper.insertSelective(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OtaInfo> getNightJob() {
|
||||
return otaInfoMapper.getJob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOtaInfo(OtaInfo info) {
|
||||
return otaInfoMapper.updateByPrimaryKeySelective(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OtaInfo getJobById(String clientId) {
|
||||
return otaInfoMapper.getOtaInfo(clientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteOtaInfo(String name, String version) {
|
||||
return otaInfoMapper.deleteOtaInfo(name,version);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,9 +76,11 @@ mqtt:
|
|||
#默认主题
|
||||
default-topic: xiuosiot/#
|
||||
#api key
|
||||
apikey: 6eea245a7f531f2f
|
||||
apikey: ac527c699ec31245
|
||||
#secret key
|
||||
secretkey: XsyKpCXGvPfWifwOjsK2J2JP3E9AouxezXm8SqaJXcYP
|
||||
secretkey: UEqxxgyY9Ba3Kebl2zlEu9Bq67n9AR9CdxDQ0iYz802XsbO
|
||||
#api url
|
||||
apiurl: http://8.140.53.225:18083
|
||||
|
||||
tdengine:
|
||||
url: jdbc:TAOS://taosnode1:6030/xiuosiot?user=root&password=taosdata
|
||||
|
|
|
@ -57,7 +57,7 @@ mybatis:
|
|||
#MQTT Config
|
||||
mqtt:
|
||||
#MQTT-服务器连接地
|
||||
hostUrl: tcp://localhost:1883
|
||||
hostUrl: tcp://115.238.53.59:1883
|
||||
#MQTT-连接服务器默认客户端ID
|
||||
clientId: xiuosiot-client
|
||||
#MQTT-用户名
|
||||
|
@ -74,6 +74,8 @@ mqtt:
|
|||
apikey: 13e1c0be6d573f86
|
||||
#secret key
|
||||
secretkey: 9BLxyWslygS5oFTz8TX5ssJ7JMiBY9CefU9B35uWx3ltqN
|
||||
#api url
|
||||
apiurl: http://115.238.53.59:18083
|
||||
tdengine:
|
||||
url: jdbc:TAOS://xiuosiot.taosnode1:6030/xiuosiot?user=root&password=taosdata
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
</rollingPolicy>
|
||||
</appender>
|
||||
<!--创建一个具体的日志输出-->
|
||||
<logger name="com.aiit" level="info" additivity="true">
|
||||
<logger name="com.aiit" level="debug" additivity="true">
|
||||
<!--可以有多个appender-ref,即将日志记录到不同的位置-->
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="fileLog"/>
|
||||
</logger>
|
||||
|
||||
<!--基础的日志输出-->
|
||||
<root level="info">
|
||||
<root level="debug">
|
||||
</root>
|
||||
</configuration>
|
|
@ -3,8 +3,8 @@
|
|||
<mapper namespace="com.aiit.xiuos.dao.mappers.DeviceInfoMapper">
|
||||
<resultMap id="BaseResultMap" type="com.aiit.xiuos.model.DeviceInfo">
|
||||
<constructor>
|
||||
<idArg column="id" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<idArg column="no" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="id" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="productname" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="type" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="activestatus" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
|
@ -31,25 +31,23 @@
|
|||
</constructor>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, no, productname, type, activestatus, updatetime, devicedesc, runstatus, statusdesc,
|
||||
no, id, productname, type, activestatus, updatetime, devicedesc, runstatus, statusdesc,
|
||||
kernel, webversion, ipaddr, netmask, gateway, dnsserver0, dnsserver1, topic, serveraddr,
|
||||
serverport, username, clientid, privateserveraddr, privateserverport, privateserverusername,
|
||||
org
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="map" resultMap="BaseResultMap">
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from device_info
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
and no = #{no,jdbcType=VARCHAR}
|
||||
where no = #{no,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="map">
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||
delete from device_info
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
and no = #{no,jdbcType=VARCHAR}
|
||||
where no = #{no,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.aiit.xiuos.model.DeviceInfo">
|
||||
insert into device_info (id, no, productname,
|
||||
insert into device_info (no, id, productname,
|
||||
type, activestatus, updatetime,
|
||||
devicedesc, runstatus, statusdesc,
|
||||
kernel, webversion, ipaddr,
|
||||
|
@ -58,7 +56,7 @@
|
|||
serverport, username, clientid,
|
||||
privateserveraddr, privateserverport, privateserverusername,
|
||||
org)
|
||||
values (#{id,jdbcType=VARCHAR}, #{no,jdbcType=VARCHAR}, #{productname,jdbcType=VARCHAR},
|
||||
values (#{no,jdbcType=VARCHAR}, #{id,jdbcType=VARCHAR}, #{productname,jdbcType=VARCHAR},
|
||||
#{type,jdbcType=VARCHAR}, #{activestatus,jdbcType=INTEGER}, #{updatetime,jdbcType=VARCHAR},
|
||||
#{devicedesc,jdbcType=VARCHAR}, #{runstatus,jdbcType=INTEGER}, #{statusdesc,jdbcType=VARCHAR},
|
||||
#{kernel,jdbcType=VARCHAR}, #{webversion,jdbcType=VARCHAR}, #{ipaddr,jdbcType=VARCHAR},
|
||||
|
@ -71,12 +69,12 @@
|
|||
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.DeviceInfo">
|
||||
insert into device_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
id,
|
||||
</if>
|
||||
<if test="no != null">
|
||||
no,
|
||||
</if>
|
||||
<if test="id != null">
|
||||
id,
|
||||
</if>
|
||||
<if test="productname != null">
|
||||
productname,
|
||||
</if>
|
||||
|
@ -148,12 +146,12 @@
|
|||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
#{id,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="no != null">
|
||||
#{no,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="id != null">
|
||||
#{id,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="productname != null">
|
||||
#{productname,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -228,6 +226,9 @@
|
|||
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.DeviceInfo">
|
||||
update device_info
|
||||
<set>
|
||||
<if test="id != null">
|
||||
id = #{id,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="productname != null">
|
||||
productname = #{productname,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
@ -298,12 +299,12 @@
|
|||
org = #{org,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
and no = #{no,jdbcType=VARCHAR}
|
||||
where no = #{no,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.DeviceInfo">
|
||||
update device_info
|
||||
set productname = #{productname,jdbcType=VARCHAR},
|
||||
set id = #{id,jdbcType=VARCHAR},
|
||||
productname = #{productname,jdbcType=VARCHAR},
|
||||
type = #{type,jdbcType=VARCHAR},
|
||||
activestatus = #{activestatus,jdbcType=INTEGER},
|
||||
updatetime = #{updatetime,jdbcType=VARCHAR},
|
||||
|
@ -326,8 +327,7 @@
|
|||
privateserverport = #{privateserverport,jdbcType=VARCHAR},
|
||||
privateserverusername = #{privateserverusername,jdbcType=VARCHAR},
|
||||
org = #{org,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
and no = #{no,jdbcType=VARCHAR}
|
||||
where no = #{no,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
||||
<select id="getDeviceTypeCount" parameterType="map" resultType="java.util.Map">
|
||||
|
|
|
@ -0,0 +1,201 @@
|
|||
<?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.aiit.xiuos.dao.mappers.LoraDeviceInfoMapper">
|
||||
<resultMap id="BaseResultMap" type="com.aiit.xiuos.model.LoraDeviceInfo">
|
||||
<constructor>
|
||||
<idArg column="dev_EUI" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="join_EUI" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="name" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="app_key" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="support_OTAA" javaType="java.lang.Boolean" jdbcType="BIT" />
|
||||
<arg column="support_ClassC" javaType="java.lang.Boolean" jdbcType="BIT" />
|
||||
<arg column="gatewayId" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark1" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark2" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark3" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark4" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="status" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
<arg column="remark5" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
</constructor>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
dev_EUI, join_EUI, name, app_key, support_OTAA, support_ClassC, gatewayId, remark1,
|
||||
remark2, org, remark3, remark4, status, remark5
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from lora_device_info
|
||||
where dev_EUI = #{devEui,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||
delete from lora_device_info
|
||||
where dev_EUI = #{devEui,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.aiit.xiuos.model.LoraDeviceInfo">
|
||||
insert into lora_device_info (dev_EUI, join_EUI, name,
|
||||
app_key, support_OTAA, support_ClassC,
|
||||
gatewayId, remark1, remark2,
|
||||
org, remark3, remark4,
|
||||
status, remark5)
|
||||
values (#{devEui,jdbcType=VARCHAR}, #{joinEui,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
|
||||
#{appKey,jdbcType=VARCHAR}, #{supportOtaa,jdbcType=BIT}, #{supportClassc,jdbcType=BIT},
|
||||
#{gatewayid,jdbcType=VARCHAR}, #{remark1,jdbcType=VARCHAR}, #{remark2,jdbcType=VARCHAR},
|
||||
#{org,jdbcType=VARCHAR}, #{remark3,jdbcType=VARCHAR}, #{remark4,jdbcType=VARCHAR},
|
||||
#{status,jdbcType=INTEGER}, #{remark5,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.LoraDeviceInfo">
|
||||
insert into lora_device_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="devEui != null">
|
||||
dev_EUI,
|
||||
</if>
|
||||
<if test="joinEui != null">
|
||||
join_EUI,
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name,
|
||||
</if>
|
||||
<if test="appKey != null">
|
||||
app_key,
|
||||
</if>
|
||||
<if test="supportOtaa != null">
|
||||
support_OTAA,
|
||||
</if>
|
||||
<if test="supportClassc != null">
|
||||
support_ClassC,
|
||||
</if>
|
||||
<if test="gatewayid != null">
|
||||
gatewayId,
|
||||
</if>
|
||||
<if test="remark1 != null">
|
||||
remark1,
|
||||
</if>
|
||||
<if test="remark2 != null">
|
||||
remark2,
|
||||
</if>
|
||||
<if test="org != null">
|
||||
org,
|
||||
</if>
|
||||
<if test="remark3 != null">
|
||||
remark3,
|
||||
</if>
|
||||
<if test="remark4 != null">
|
||||
remark4,
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status,
|
||||
</if>
|
||||
<if test="remark5 != null">
|
||||
remark5,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="devEui != null">
|
||||
#{devEui,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="joinEui != null">
|
||||
#{joinEui,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
#{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="appKey != null">
|
||||
#{appKey,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="supportOtaa != null">
|
||||
#{supportOtaa,jdbcType=BIT},
|
||||
</if>
|
||||
<if test="supportClassc != null">
|
||||
#{supportClassc,jdbcType=BIT},
|
||||
</if>
|
||||
<if test="gatewayid != null">
|
||||
#{gatewayid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark1 != null">
|
||||
#{remark1,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark2 != null">
|
||||
#{remark2,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="org != null">
|
||||
#{org,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark3 != null">
|
||||
#{remark3,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark4 != null">
|
||||
#{remark4,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
#{status,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="remark5 != null">
|
||||
#{remark5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.LoraDeviceInfo">
|
||||
update lora_device_info
|
||||
<set>
|
||||
<if test="joinEui != null">
|
||||
join_EUI = #{joinEui,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="appKey != null">
|
||||
app_key = #{appKey,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="supportOtaa != null">
|
||||
support_OTAA = #{supportOtaa,jdbcType=BIT},
|
||||
</if>
|
||||
<if test="supportClassc != null">
|
||||
support_ClassC = #{supportClassc,jdbcType=BIT},
|
||||
</if>
|
||||
<if test="gatewayid != null">
|
||||
gatewayId = #{gatewayid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark1 != null">
|
||||
remark1 = #{remark1,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark2 != null">
|
||||
remark2 = #{remark2,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="org != null">
|
||||
org = #{org,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark3 != null">
|
||||
remark3 = #{remark3,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark4 != null">
|
||||
remark4 = #{remark4,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="remark5 != null">
|
||||
remark5 = #{remark5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where dev_EUI = #{devEui,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.LoraDeviceInfo">
|
||||
update lora_device_info
|
||||
set join_EUI = #{joinEui,jdbcType=VARCHAR},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
app_key = #{appKey,jdbcType=VARCHAR},
|
||||
support_OTAA = #{supportOtaa,jdbcType=BIT},
|
||||
support_ClassC = #{supportClassc,jdbcType=BIT},
|
||||
gatewayId = #{gatewayid,jdbcType=VARCHAR},
|
||||
remark1 = #{remark1,jdbcType=VARCHAR},
|
||||
remark2 = #{remark2,jdbcType=VARCHAR},
|
||||
org = #{org,jdbcType=VARCHAR},
|
||||
remark3 = #{remark3,jdbcType=VARCHAR},
|
||||
remark4 = #{remark4,jdbcType=VARCHAR},
|
||||
status = #{status,jdbcType=INTEGER},
|
||||
remark5 = #{remark5,jdbcType=VARCHAR}
|
||||
where dev_EUI = #{devEui,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
|
@ -0,0 +1,166 @@
|
|||
<?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.aiit.xiuos.dao.mappers.LoraGatewayInfoMapper">
|
||||
<resultMap id="BaseResultMap" type="com.aiit.xiuos.model.LoraGatewayInfo">
|
||||
<constructor>
|
||||
<idArg column="gatewayId" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="name" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="device_num" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
<arg column="last_connect" javaType="java.util.Date" jdbcType="TIMESTAMP" />
|
||||
<arg column="status" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
<arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark1" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark2" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark3" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark4" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="remark5" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
</constructor>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
gatewayId, name, device_num, last_connect, status, org, remark1, remark2, remark3,
|
||||
remark4, remark5
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from lora_gateway_info
|
||||
where gatewayId = #{gatewayid,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||
delete from lora_gateway_info
|
||||
where gatewayId = #{gatewayid,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.aiit.xiuos.model.LoraGatewayInfo">
|
||||
insert into lora_gateway_info (gatewayId, name, device_num,
|
||||
last_connect, status, org,
|
||||
remark1, remark2, remark3,
|
||||
remark4, remark5)
|
||||
values (#{gatewayid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{deviceNum,jdbcType=INTEGER},
|
||||
#{lastConnect,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, #{org,jdbcType=VARCHAR},
|
||||
#{remark1,jdbcType=VARCHAR}, #{remark2,jdbcType=VARCHAR}, #{remark3,jdbcType=VARCHAR},
|
||||
#{remark4,jdbcType=VARCHAR}, #{remark5,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.LoraGatewayInfo">
|
||||
insert into lora_gateway_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="gatewayid != null">
|
||||
gatewayId,
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name,
|
||||
</if>
|
||||
<if test="deviceNum != null">
|
||||
device_num,
|
||||
</if>
|
||||
<if test="lastConnect != null">
|
||||
last_connect,
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status,
|
||||
</if>
|
||||
<if test="org != null">
|
||||
org,
|
||||
</if>
|
||||
<if test="remark1 != null">
|
||||
remark1,
|
||||
</if>
|
||||
<if test="remark2 != null">
|
||||
remark2,
|
||||
</if>
|
||||
<if test="remark3 != null">
|
||||
remark3,
|
||||
</if>
|
||||
<if test="remark4 != null">
|
||||
remark4,
|
||||
</if>
|
||||
<if test="remark5 != null">
|
||||
remark5,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="gatewayid != null">
|
||||
#{gatewayid,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
#{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="deviceNum != null">
|
||||
#{deviceNum,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="lastConnect != null">
|
||||
#{lastConnect,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
#{status,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="org != null">
|
||||
#{org,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark1 != null">
|
||||
#{remark1,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark2 != null">
|
||||
#{remark2,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark3 != null">
|
||||
#{remark3,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark4 != null">
|
||||
#{remark4,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark5 != null">
|
||||
#{remark5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.LoraGatewayInfo">
|
||||
update lora_gateway_info
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="deviceNum != null">
|
||||
device_num = #{deviceNum,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="lastConnect != null">
|
||||
last_connect = #{lastConnect,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="org != null">
|
||||
org = #{org,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark1 != null">
|
||||
remark1 = #{remark1,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark2 != null">
|
||||
remark2 = #{remark2,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark3 != null">
|
||||
remark3 = #{remark3,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark4 != null">
|
||||
remark4 = #{remark4,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="remark5 != null">
|
||||
remark5 = #{remark5,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where gatewayId = #{gatewayid,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.LoraGatewayInfo">
|
||||
update lora_gateway_info
|
||||
set name = #{name,jdbcType=VARCHAR},
|
||||
device_num = #{deviceNum,jdbcType=INTEGER},
|
||||
last_connect = #{lastConnect,jdbcType=TIMESTAMP},
|
||||
status = #{status,jdbcType=INTEGER},
|
||||
org = #{org,jdbcType=VARCHAR},
|
||||
remark1 = #{remark1,jdbcType=VARCHAR},
|
||||
remark2 = #{remark2,jdbcType=VARCHAR},
|
||||
remark3 = #{remark3,jdbcType=VARCHAR},
|
||||
remark4 = #{remark4,jdbcType=VARCHAR},
|
||||
remark5 = #{remark5,jdbcType=VARCHAR}
|
||||
where gatewayId = #{gatewayid,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
|
@ -0,0 +1,155 @@
|
|||
<?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.aiit.xiuos.dao.mappers.OtaInfoMapper">
|
||||
<resultMap id="BaseResultMap" type="com.aiit.xiuos.model.OtaInfo">
|
||||
<constructor>
|
||||
<idArg column="id" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
<arg column="file_name" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="device_id" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="current_process" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
<arg column="status" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
<arg column="create_time" javaType="java.util.Date" jdbcType="TIMESTAMP" />
|
||||
<arg column="update_type" javaType="java.lang.Integer" jdbcType="INTEGER" />
|
||||
<arg column="timeout" javaType="java.util.Date" jdbcType="TIMESTAMP" />
|
||||
<arg column="file_version" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
<arg column="org" javaType="java.lang.String" jdbcType="VARCHAR" />
|
||||
</constructor>
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, file_name, device_id, current_process, status, create_time, update_type, timeout,
|
||||
file_version, org
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from ota_info
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from ota_info
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.aiit.xiuos.model.OtaInfo">
|
||||
insert into ota_info (id, file_name, device_id,
|
||||
current_process, status, create_time,
|
||||
update_type, timeout, file_version,
|
||||
org)
|
||||
values (#{id,jdbcType=INTEGER}, #{fileName,jdbcType=VARCHAR}, #{deviceId,jdbcType=VARCHAR},
|
||||
#{currentProcess,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
|
||||
#{updateType,jdbcType=INTEGER}, #{timeout,jdbcType=TIMESTAMP}, #{fileVersion,jdbcType=VARCHAR},
|
||||
#{org,jdbcType=VARCHAR})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.OtaInfo">
|
||||
insert into ota_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
id,
|
||||
</if>
|
||||
<if test="fileName != null">
|
||||
file_name,
|
||||
</if>
|
||||
<if test="deviceId != null">
|
||||
device_id,
|
||||
</if>
|
||||
<if test="currentProcess != null">
|
||||
current_process,
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updateType != null">
|
||||
update_type,
|
||||
</if>
|
||||
<if test="timeout != null">
|
||||
timeout,
|
||||
</if>
|
||||
<if test="fileVersion != null">
|
||||
file_version,
|
||||
</if>
|
||||
<if test="org != null">
|
||||
org,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">
|
||||
#{id,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="fileName != null">
|
||||
#{fileName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="deviceId != null">
|
||||
#{deviceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="currentProcess != null">
|
||||
#{currentProcess,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
#{status,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateType != null">
|
||||
#{updateType,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="timeout != null">
|
||||
#{timeout,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="fileVersion != null">
|
||||
#{fileVersion,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="org != null">
|
||||
#{org,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.OtaInfo">
|
||||
update ota_info
|
||||
<set>
|
||||
<if test="fileName != null">
|
||||
file_name = #{fileName,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="deviceId != null">
|
||||
device_id = #{deviceId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="currentProcess != null">
|
||||
current_process = #{currentProcess,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateType != null">
|
||||
update_type = #{updateType,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="timeout != null">
|
||||
timeout = #{timeout,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="fileVersion != null">
|
||||
file_version = #{fileVersion,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="org != null">
|
||||
org = #{org,jdbcType=VARCHAR},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.OtaInfo">
|
||||
update ota_info
|
||||
set file_name = #{fileName,jdbcType=VARCHAR},
|
||||
device_id = #{deviceId,jdbcType=VARCHAR},
|
||||
current_process = #{currentProcess,jdbcType=INTEGER},
|
||||
status = #{status,jdbcType=INTEGER},
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
update_type = #{updateType,jdbcType=INTEGER},
|
||||
timeout = #{timeout,jdbcType=TIMESTAMP},
|
||||
file_version = #{fileVersion,jdbcType=VARCHAR},
|
||||
org = #{org,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
Loading…
Reference in New Issue