This commit is contained in:
龚祖望 2023-07-26 17:41:38 +08:00
commit cc406f18f8
22 changed files with 436 additions and 159 deletions

View File

@ -155,7 +155,13 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!--junit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
@ -222,6 +228,7 @@
<includes>
<include>*.yml</include>
<include>**/*.xml</include>
<include>**/*.txt</include>
</includes>
<filtering>false</filtering>
</resource>

View File

@ -39,6 +39,10 @@ public class AroundLogAspect {
public void excludeLogPointcut() {
}
@Pointcut("execution(* com.aiit.xiuos.controller.DeviceDataController.*(..))")
public void excludeData() {
}
@Pointcut("execution(* com.aiit.xiuos.controller.UserController.*(..))")
public void excludeUserPointcut() {
}
@ -47,7 +51,7 @@ public class AroundLogAspect {
public void excludeController() {
}
@Pointcut("normalPointcut() && !excludeUserPointcut()&& !excludeLogPointcut()&&!excludeController()")
@Pointcut("normalPointcut() && !excludeUserPointcut()&& !excludeLogPointcut()&&!excludeController()&&!excludeData()")
public void pointCutMethod() {
}

View File

@ -1,148 +1,174 @@
package com.aiit.xiuos.Utils;
import com.alibaba.fastjson.JSONObject;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
public class HexUtil {
public static byte[] hexStringToBytes(String hexString) {
if (hexString == null || hexString.equals("")) {
return null;
}
// toUpperCase将字符串中的所有字符转换为大写
hexString = hexString.toUpperCase();
int length = hexString.length() / 2;
// toCharArray将此字符串转换为一个新的字符数组
char[] hexChars = hexString.toCharArray();
byte[] d = new byte[length];
for (int i = 0; i < length; i++) {
int pos = i * 2;
d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
}
return d;
}
//charToByte返回在指定字符的第一个发生的字符串中的索引即返回匹配字符
private static byte charToByte(char c) {
return (byte) "0123456789ABCDEF".indexOf(c);
}
public static JSONObject hexToString(Boolean flag,String split,String hex,int[] valueLen,String [] valueName){
String res ="";
//去掉0X前缀
if(flag){
res= hex.replaceAll("0x","");
}
//将分隔符变为空
if(split!=null){
res=res.replaceAll(split,"");
}
public static String BinaryToHexString(byte[] bytes) {
String hexStr = "0123456789ABCDEF";
String result = "";
String hex = "";
for (byte b : bytes) {
hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4));
hex += String.valueOf(hexStr.charAt(b & 0x0F));
result += hex ;
}
return result;
}
int length = valueLen[valueLen.length-1];
//两位一字符倒序排序
public static String reverseString(String str) {
// if(length!=res.length()){
// System.out.println("字符长度不对,请检查!");
// }
List<String> strlist=new ArrayList();
JSONObject jsonObject = new JSONObject();
int tempIndex = 0;
char[] chr = str.toCharArray();
for (int i = 0; i <valueLen.length ; i++) {
String s = res.substring(tempIndex,tempIndex+valueLen[i]);
int n = Integer.parseInt(s,16);
jsonObject.put(valueName[i],n);
tempIndex+=valueLen[i];
for (int i = 0 ; i < chr.length; i=i+2) {
}
String s=chr[i]+""+chr[i+1];
return jsonObject;
strlist.add(s);
}
}
Collections.reverse(strlist);
public static void main(String args[]){
String result="";
System.out.println(hexToFloat("442e816a"));
for(String v:strlist){
result+=v;
}
return result;
}
//十六进制转浮点数
public static float hexToFloat(String hex){
BigInteger b = new BigInteger(hex, 16);
float value = Float.intBitsToFloat(b.intValue());
System.out.println(value);
return value;
}
//十六进制转整数
public static int unSignedHexToDec(String hex){
int decimal = Integer.parseInt(hex, 16);
System.out.println(decimal);
return decimal;
}
/**
* 16进制转换成为string类型字符串
* @param s
* 有符号16进制转10进制
* @param strHex
* @return
*/
public static String hexStringToString(String s) {
if (s == null || s.equals("")) {
return null;
public static int signedHexToDec(String strHex){
if(strHex.length()==0){
return 0;
}
s = s.replace(" ", "");
byte[] baKeyword = new byte[s.length() / 2];
for (int i = 0; i < baKeyword.length; i++) {
try {
baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
} catch (Exception e) {
e.printStackTrace();
int x = 0;
//带符号十六进制转换十进制
String fristNum = strHex.substring(0, 1);
String hexStr2Byte = hexStrToByte(fristNum);
String flag = hexStr2Byte.substring(0, 1);
if("1".equals(flag)){
StringBuffer sb = new StringBuffer();
for (int i = 0; i < strHex.length(); i++) {
String num = strHex.substring(i, i+1);
int decNum = Integer.parseInt(num,16);
int a = decNum^15;
sb.append(intToHex(a));
}
x = -Integer.parseInt(sb.toString(),16)-1;
}else{
x = Integer.parseInt(strHex,16);
}
try {
s = new String(baKeyword, "UTF-8");
new String();
} catch (Exception e1) {
e1.printStackTrace();
}
return s;
return x;
}
/**
* 字符串转化成为16进制字符串
* @param s
* @return
*/
public static String strTo16(String s) {
String str = "";
for (int i = 0; i < s.length(); i++) {
int ch = (int) s.charAt(i);
String s4 = Integer.toHexString(ch);
str = str + s4;
//十进制转16进制
private static String intToHex(int n) {
StringBuffer s = new StringBuffer();
String a;
char []b = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
while(n != 0){
s = s.append(b[n%16]);
n = n/16;
}
return str;
}
//将16进制字符串自动补全到8位 并且倒序排序
public static String full8(String lenth) {
int a = lenth.getBytes().length;
int b = 8 - a;
for (int i = 0; i < b; i++) {
lenth = "0" + lenth;
}
return reverseString(lenth);
a = s.reverse().toString();
return a;
}
/**
* xor运算
* 将16进制转换为二进制
*
* @param data
* @param hexStr
* @return
*/
public static String getBCC(byte[] data) {
String ret = "";
byte BCC[] = new byte[1];
for (int i = 0; i < data.length; i++) {
BCC[0] = (byte) (BCC[0] ^ data[i]);
public static String hexStrToByte(String hexStr) {
if (hexStr.length() == 0)
return null;
int sint=Integer.valueOf(hexStr, 16);
//十进制在转换成二进制的字符串形式输出!
String bin=Integer.toBinaryString(sint);
for (int i = bin.length(); i < 4; i++) {
bin = "0"+bin;
}
String hex = Integer.toHexString(BCC[0] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
return bin;
}
/**
* 16进制直接转换成为字符串(无需Unicode解码)
* @param hexStr Byte字符串(Byte之间无分隔符
* @author xxs
* @return 对应的字符串
*/
public static String hexStrToStr(String hexStr) {
String str = "0123456789ABCDEF"; //16进制能用到的所有字符 0-15
char[] hexs = hexStr.toCharArray();//toCharArray() 方法将字符串转换为字符数组
int length = (hexStr.length() / 2);//1个byte数值 -> 两个16进制字符
byte[] bytes = new byte[length];
int n;
for (int i = 0; i < bytes.length; i++) {
int position = i * 2;//两个16进制字符 -> 1个byte数值
n = str.indexOf(hexs[position]) * 16;
n += str.indexOf(hexs[position + 1]);
// 保持二进制补码的一致性 因为byte类型字符是8bit的 而int为32bit 会自动补齐高位1 所以与上0xFF之后可以保持高位一致性
//当byte要转化为int的时候高的24位必然会补1这样其二进制补码其实已经不一致了&0xff可以将高的24位置为0低8位保持原样这样做的目的就是为了保证二进制数据的一致性
bytes[i] = (byte) (n & 0xff);
}
ret += hex.toUpperCase();
return ret;
return new String(bytes);
}
/**
* 字符串转换成为16进制(无需Unicode编码)
* @param str 待转换的ASCII字符串
* @author xxs
* @return byte字符串 每个Byte之间空格分隔
*/
public static String str2HexStr(String str) {
char[] chars = "0123456789ABCDEF".toCharArray();//toCharArray() 方法将字符串转换为字符数组
StringBuilder sb = new StringBuilder(""); //StringBuilder是一个类可以用来处理字符串,sb.append()字符串相加效率高
byte[] bs = str.getBytes();//String的getBytes()方法是得到一个操作系统默认的编码格式的字节数组
int bit;
for (int i = 0; i < bs.length; i++) {
bit = (bs[i] & 0x0f0) >> 4; // 高4位, 与操作 1111 0000
sb.append(chars[bit]);
bit = bs[i] & 0x0f; // 低四位, 与操作 0000 1111
sb.append(chars[bit]);
sb.append(' ');//每个Byte之间空格分隔
}
return sb.toString().trim();
}
}

View File

@ -33,8 +33,8 @@ public class DeviceController {
deviceInfo.setUpdatetime(MyUtils.getTime());
deviceInfo.setOrg(userInfo.getOrg());
boolean flag = TDengineJDBCUtil.createTable(deviceInfo.getNo(),deviceInfo.getType(),deviceInfo.getOrg(),deviceInfo.getProductname());
//boolean flag = TDengineJDBCUtil.createTable(deviceInfo.getNo(),deviceInfo.getType(),deviceInfo.getOrg(),deviceInfo.getProductname());
boolean flag =true;
if(flag) {
int res=deviceInfoService.addDevice(deviceInfo);
if(1==res){

View File

@ -5,10 +5,12 @@ import com.aiit.xiuos.Utils.Constant;
import com.aiit.xiuos.Utils.HttpClientUtil;
import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.AvgDayData;
import com.aiit.xiuos.model.GZJCData;
import com.aiit.xiuos.model.QjdqElectric;
import com.aiit.xiuos.mqtt.MqttConfiguration;
import com.aiit.xiuos.mqtt.MyMqttClient;
import com.aiit.xiuos.service.AvgDayDataService;
import com.aiit.xiuos.service.GZJCService;
import com.aiit.xiuos.service.QjdqElectricService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,6 +31,8 @@ public class DeviceDataController {
private MyMqttClient myMqttClient;
@Autowired
private QjdqElectricService qjdqElectricService;
@Autowired
private GZJCService gzjcService;
@GetMapping("/getAll")
public ResultRespons getAllDataFromDSD(HttpServletRequest request){
@ -67,6 +71,15 @@ public class DeviceDataController {
return new ResultRespons(Constant.ERROR_CODE,"查询数据失败");
}
@GetMapping("/getGZJC")
public ResultRespons getGZJC(){
List<GZJCData> GZJCDatas = gzjcService.selectData();
if(GZJCDatas!=null&&GZJCDatas.size()>0){
return new ResultRespons(Constant.SUCCESS_CODE,"查询数据成功!",GZJCDatas);
}
return new ResultRespons(Constant.ERROR_CODE,"查询数据失败");
}
}

View File

@ -0,0 +1,29 @@
package com.aiit.xiuos.controller;
import com.aiit.xiuos.Utils.Constant;
import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.AlarmRule;
import com.aiit.xiuos.service.AlarmRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/rule")
public class DeviceDataRuleController {
@Autowired
AlarmRuleService alarmRuleService;
@PostMapping("/add")
public ResultRespons addRule(@RequestBody AlarmRule alarmRule, HttpServletRequest request){
int res = alarmRuleService.addAlarmRule(alarmRule);
if(res==1){
return new ResultRespons(Constant.SUCCESS_CODE,"新增告警规则成功!");
}
return new ResultRespons(Constant.ERROR_CODE,"新增告警规则失败");
}
}

View File

@ -4,6 +4,7 @@ import com.aiit.xiuos.Utils.Constant;
import com.aiit.xiuos.Utils.MyUtils;
import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.UserInfo;
import com.aiit.xiuos.redis.RedisUtil;
import com.aiit.xiuos.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -12,12 +13,16 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@RestController
@Slf4j
public class LoginController {
@Autowired
private UserInfoService userInfoService;
@Autowired
private RedisUtil redisUtil;
@PostMapping("/login")
public ResultRespons login (@RequestBody UserInfo userInfo, HttpServletRequest request) {
@ -25,10 +30,12 @@ public class LoginController {
if(null!=user){
HttpSession session = request.getSession();
session.setAttribute("user",user);//session存用户
log.info("session======="+session.getId());
// Map<String,Object> users=new HashMap<>();
// users.put(user.getUsername(),user);
// redisUtil.hset("xiuosuser",users,-1);
// users=redisUtil.hget("xiuosuser",-1);
String ip = MyUtils.getIp(request);
userInfoService.updateLoginInfo(MyUtils.getTime(),ip,user.getId());
log.info("ip++++++++===="+ip);
return new ResultRespons(Constant.SUCCESS_CODE,"登录成功");
}
return new ResultRespons(Constant.ERROR_CODE,"登录失败,用户名或密码有误");
@ -40,6 +47,7 @@ public class LoginController {
HttpSession session = request.getSession();
session.removeAttribute("user");
session.invalidate();
redisUtil.delete("user");
return new ResultRespons(Constant.SUCCESS_CODE,"用户登出");
}

View File

@ -0,0 +1,79 @@
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 lombok.extern.slf4j.Slf4j;
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 java.util.List;
@RestController
@RequestMapping("/ota")
@Slf4j
public class OTAController {
/*
上传接口
*/
//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("/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, "下载成功");
}else{
return new ResultRespons(Constant.ERROR_CODE, "文件名不存在");
}
} catch (Exception e) {
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, "文件不存在");
}
}
}

View File

@ -5,6 +5,7 @@ import com.aiit.xiuos.Utils.GenerateIdUtil;
import com.aiit.xiuos.Utils.MyUtils;
import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.UserInfo;
import com.aiit.xiuos.redis.RedisUtil;
import com.aiit.xiuos.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -17,6 +18,8 @@ import javax.servlet.http.HttpSession;
public class UserController {
@Autowired
private UserInfoService userInfoService;
@Autowired
private RedisUtil redisUtil;
@PostMapping("/register")
public ResultRespons addUser (@RequestBody UserInfo userInfo, HttpServletRequest request) {
@ -35,6 +38,7 @@ public class UserController {
@GetMapping("/getSession")
public Object getPermission(HttpServletRequest request) {
//UserInfo userInfo=redisUtil.get("user",UserInfo.class);
UserInfo userInfo =(UserInfo) request.getSession().getAttribute("user");
if(userInfo==null){
return new ResultRespons(Constant.SessionTimeOut_CODE,"用户尚未登录,请先登录!");

View File

@ -0,0 +1,17 @@
package com.aiit.xiuos.dao.mappers;
import com.aiit.xiuos.model.DeviceDataRule;
public interface DeviceDataRuleMapper {
int deleteByPrimaryKey(Integer ruleid);
int insert(DeviceDataRule record);
int insertSelective(DeviceDataRule record);
DeviceDataRule selectByPrimaryKey(Integer ruleid);
int updateByPrimaryKeySelective(DeviceDataRule record);
int updateByPrimaryKey(DeviceDataRule record);
}

View File

@ -4,6 +4,8 @@ import com.aiit.xiuos.model.GZJCData;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface GZJCDataMapper {
int deleteByPrimaryKey(Integer id);
@ -19,6 +21,6 @@ public interface GZJCDataMapper {
int updateByPrimaryKey(GZJCData record);
@Select("select * from haier_data order by time desc limit 1")
GZJCData selectData();
@Select("select windspeed,winddirection,airpressure,noise from gzjc_data order by time desc limit 12")
List<GZJCData> selectData();
}

View File

@ -0,0 +1,27 @@
package com.aiit.xiuos.model;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class DeviceDataRule {
private Integer ruleid;
private Integer datacount;
private String datastring;
private String remark;
public DeviceDataRule(Integer ruleid, Integer datacount, String datastring, String remark) {
this.ruleid = ruleid;
this.datacount = datacount;
this.datastring = datastring;
this.remark = remark;
}
public DeviceDataRule() {
super();
}
}

View File

@ -16,6 +16,7 @@ public class PushCallback implements MqttCallbackExtended {
@Override
public void connectionLost(Throwable throwable) {
log.error("mqtt lose connect:"+throwable) ;
long reconnectTimes = 1;
while (true) {
try {

View File

@ -34,7 +34,7 @@ public class GZJCTaskScheduled {
}
@Scheduled(cron = "*/1 * * * * ?")//every hour
@Scheduled(cron = "0 */1 * * * ?")//every hour
public void sendWebsocket() throws ParseException, IOException {
GZJCData GZJCData = mockData();
JSONObject jsonObject = JSONUtil.parseObj(GZJCData,false,true);
@ -102,10 +102,10 @@ public class GZJCTaskScheduled {
double winddirection = rand.nextInt(30)+200; //风向
GZJCData.setWinddirection(new BigDecimal(df.format(winddirection)));
double airpressure=rand.nextInt(100)+900+Math.random(); //气压
double airpressure=rand.nextInt(100)+900; //气压
GZJCData.setAirpressure(new BigDecimal(df.format(airpressure)));
double noise =rand.nextInt(71)+30+Math.random(); //噪音 pd
double noise =rand.nextInt(70)+30+Math.random(); //噪音 pd
GZJCData.setNoise(new BigDecimal(df.format(noise)));

View File

@ -180,7 +180,6 @@ public class TaskScheduled {
arrayList.add(qjdqElectric.getElectric39());
newRecord.setElectric40(qjdqElectric.getElectric40().add(new BigDecimal(Math.random())));
arrayList.add(qjdqElectric.getElectric40());
log.info( "返回数据"+arrayList.toString());
qjdqWebSocketServer.sendInfo(arrayList.toString());
qjdqElectricService.updateElectric(newRecord);
@ -206,7 +205,7 @@ public class TaskScheduled {
}
//取前一天数据
tdString+="ts>now-1d";
log.info("sql+++++++++:"+tdString);
log.info("执行规则sql为:"+tdString);
//去Tdengine执行sql
int count = 0;
AlarmInfo alarmInfo = new AlarmInfo();
@ -245,5 +244,15 @@ public class TaskScheduled {
}
}
}
// @Scheduled(cron = "0 */1 8-20 * * ?")//every minute 8-20 clock
// public void mockXiuosData(){
// String DsdDevices[]={"A000001","A000005","A000006","A000007","A000008","A000009","A000010","s02","s01","s05","s03","q000001"};
// for(int i=0;i<DsdDevices.length;i++){
// String sql = "insert into "+DsdDevices[i]+" values(now,12,12,18,28);";
// TDengineJDBCUtil.executeInsertSql(sql);
// }
// }
}

View File

@ -0,0 +1,10 @@
package com.aiit.xiuos.service;
import com.aiit.xiuos.model.DeviceDataRule;
public interface DeviceDataRuleService {
int addDataRule(DeviceDataRule deviceDataRule);
int updateDataRule(DeviceDataRule deviceDataRule);
int deleteDataRule(int ruleId);
DeviceDataRule selectDataRule(int ruleId);
}

View File

@ -2,7 +2,9 @@ package com.aiit.xiuos.service;
import com.aiit.xiuos.model.GZJCData;
import java.util.List;
public interface GZJCService {
int insertData(GZJCData data);
GZJCData selectData();
List<GZJCData> selectData();
}

View File

@ -0,0 +1,32 @@
package com.aiit.xiuos.service.impl;
import com.aiit.xiuos.dao.mappers.DeviceDataRuleMapper;
import com.aiit.xiuos.model.DeviceDataRule;
import com.aiit.xiuos.service.DeviceDataRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DeviceDataRuleServiceImpl implements DeviceDataRuleService {
@Autowired
DeviceDataRuleMapper deviceDataRuleMapper;
@Override
public int addDataRule(DeviceDataRule deviceDataRule) {
return deviceDataRuleMapper.insertSelective(deviceDataRule);
}
@Override
public int updateDataRule(DeviceDataRule deviceDataRule) {
return deviceDataRuleMapper.updateByPrimaryKeySelective(deviceDataRule);
}
@Override
public int deleteDataRule(int ruleId) {
return deviceDataRuleMapper.deleteByPrimaryKey(ruleId);
}
@Override
public DeviceDataRule selectDataRule(int ruleId) {
return deviceDataRuleMapper.selectByPrimaryKey(ruleId);
}
}

View File

@ -7,17 +7,19 @@ import com.aiit.xiuos.service.GZJCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class GZJCServiceImpl implements GZJCService {
@Autowired
GZJCDataMapper haierDataMapper;
GZJCDataMapper gzjcDataMapper;
@Override
public int insertData(GZJCData data) {
return haierDataMapper.insertSelective(data);
return gzjcDataMapper.insertSelective(data);
}
@Override
public GZJCData selectData() {
return haierDataMapper.selectData();
public List<GZJCData> selectData() {
return gzjcDataMapper.selectData();
}
}

View File

@ -32,35 +32,35 @@ public class TDengineJDBCUtil {
}
public static boolean createTable(String deviceno, String type, String org, String productname){
Connection connection = null;
try {
connection = TDengineJDBCUtil.getConn();
Statement stmt = connection.createStatement();
String devicetype=TDengineJDBCUtil.changeType(type);
if(devicetype==null){
return false;
}
// create table
String sql ="create table if not exists " + deviceno + " using "+devicetype+" tags("+"\""+org+"\","+"\"" + productname+"\")";
stmt.executeUpdate(sql);
return true;
} catch (Exception e) {
log.error(e.getMessage());
}finally {
try {
if(connection!=null){
connection.close();
}
// public static boolean createTable(String deviceno, String type, String org, String productname){
// Connection connection = null;
// try {
// connection = TDengineJDBCUtil.getConn();
// Statement stmt = connection.createStatement();
// String devicetype=TDengineJDBCUtil.changeType(type);
// if(devicetype==null){
// return false;
// }
// // create table
// String sql ="create table if not exists " + deviceno + " using "+devicetype+" tags("+"\""+org+"\","+"\"" + productname+"\")";
// stmt.executeUpdate(sql);
// return true;
// } catch (Exception e) {
// log.error(e.getMessage());
// }finally {
// try {
// if(connection!=null){
// connection.close();
// }
//
// } catch (SQLException throwables) {
// throwables.printStackTrace();
// }
//
// }
// return false;
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
return false;
}
// }
public static String changeType(String type){
if(type.equals("M168-LoRa-FM100")) return "M168_LoRa_FM100";

View File

@ -0,0 +1,5 @@
__ _____ _ _ ___ ____ ___ ___ _____
\ \/ /_ _| | | |/ _ \/ ___|_ _/ _ \_ _|
\ / | || | | | | | \___ \| | | | || |
/ \ | || |_| | |_| |___) | | |_| || |
/_/\_\___|\___/ \___/|____/___\___/ |_| is started

View File

@ -34,15 +34,15 @@
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from haier_data
from gzjc_data
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from haier_data
delete from gzjc_data
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.aiit.xiuos.model.GZJCData">
insert into haier_data (id, o3, co2,
insert into gzjc_data (id, o3, co2,
so2, no2, nh3, tvoc,
ch2o, c2h5oh, ch4,
o2, aqs, humidness,
@ -60,7 +60,7 @@
)
</insert>
<insert id="insertSelective" parameterType="com.aiit.xiuos.model.GZJCData">
insert into haier_data
insert into gzjc_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
@ -199,7 +199,7 @@
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.aiit.xiuos.model.GZJCData">
update haier_data
update gzjc_data
<set>
<if test="o3 != null">
o3 = #{o3,jdbcType=NUMERIC},
@ -268,7 +268,7 @@
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.aiit.xiuos.model.GZJCData">
update haier_data
update gzjc_data
set o3 = #{o3,jdbcType=NUMERIC},
co2 = #{co2,jdbcType=NUMERIC},
so2 = #{so2,jdbcType=NUMERIC},