add log for xiuosiot
This commit is contained in:
parent
e4d0c4cb33
commit
71f0c69ef0
|
@ -17,7 +17,6 @@ import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
|
@ -37,10 +36,18 @@ public class AroundLogAspect {
|
||||||
public void normalPointcut() {
|
public void normalPointcut() {
|
||||||
}
|
}
|
||||||
@Pointcut("execution(* com.aiit.xiuos.controller.LoginController.*(..))")
|
@Pointcut("execution(* com.aiit.xiuos.controller.LoginController.*(..))")
|
||||||
public void excludePointcut() {
|
public void excludeLogPointcut() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pointcut("normalPointcut() && !excludePointcut()")
|
@Pointcut("execution(* com.aiit.xiuos.controller.UserController.*(..))")
|
||||||
|
public void excludeUserPointcut() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Pointcut("execution(* com.aiit.xiuos.controller.ExcludeController.*(..))")
|
||||||
|
public void excludeController() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Pointcut("normalPointcut() && !excludeUserPointcut()&& !excludeLogPointcut()&&!excludeController()")
|
||||||
public void pointCutMethod() {
|
public void pointCutMethod() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,25 +94,26 @@ public class AroundLogAspect {
|
||||||
requestLogInfo.setMethodname(methodName);
|
requestLogInfo.setMethodname(methodName);
|
||||||
//参数名
|
//参数名
|
||||||
Parameter[] parameters = method.getParameters();
|
Parameter[] parameters = method.getParameters();
|
||||||
|
String param ="";
|
||||||
requestLogInfo.setRequestparam(parameters[0].getName());
|
for(int i=0;i<parameters.length;i++){
|
||||||
|
param+=parameters[i]+",";
|
||||||
|
}
|
||||||
|
requestLogInfo.setRequestparam(param);
|
||||||
//计时开始
|
//计时开始
|
||||||
started.start();
|
started.start();
|
||||||
|
|
||||||
ResultRespons proceed = (ResultRespons) point.proceed();
|
ResultRespons proceed = (ResultRespons) point.proceed();
|
||||||
//计时结束
|
//计时结束
|
||||||
started.stop();
|
started.stop();
|
||||||
|
|
||||||
//请求耗时
|
//请求耗时
|
||||||
requestLogInfo.setProcesstime(String.valueOf(started.getTotalTimeMillis()));
|
requestLogInfo.setProcesstime(String.valueOf(started.getTotalTimeMillis()));
|
||||||
|
log.info("method:"+methodName);
|
||||||
log.info("processtime:"+started.getTotalTimeMillis());
|
log.info("processtime:"+started.getTotalTimeMillis());
|
||||||
//请求结果
|
//请求结果
|
||||||
requestLogInfo.setRequestresult("resultCoe="+proceed.getCode()+" resultMsg="+proceed.getMessage());
|
requestLogInfo.setRequestresult("resultCoe="+proceed.getCode()+" resultMsg="+proceed.getMessage());
|
||||||
|
|
||||||
requestLogInfoService.addLog(requestLogInfo);
|
requestLogInfoService.addLog(requestLogInfo);
|
||||||
return proceed;
|
return proceed;
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.aiit.xiuos.Utils;
|
package com.aiit.xiuos.Utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.mail.SimpleMailMessage;
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
@ -10,6 +11,7 @@ import org.springframework.stereotype.Component;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class EmailUtil {
|
public class EmailUtil {
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ public class EmailUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
// 发送邮件
|
// 发送邮件
|
||||||
mailSender.send(mimeMessage);
|
mailSender.send(mimeMessage);
|
||||||
|
@ -83,7 +85,7 @@ public class EmailUtil {
|
||||||
helper.setText(content); // 设置邮件内容
|
helper.setText(content); // 设置邮件内容
|
||||||
helper.addAttachment(file.getName(), file); // 单个附件
|
helper.addAttachment(file.getName(), file); // 单个附件
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
// 发送邮件
|
// 发送邮件
|
||||||
mailSender.send(mimeMessage);
|
mailSender.send(mimeMessage);
|
||||||
|
|
|
@ -2,14 +2,19 @@ package com.aiit.xiuos.Utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.ParseException;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -20,7 +25,16 @@ public class HttpClientUtil {
|
||||||
|
|
||||||
private static String tokenString = "";
|
private static String tokenString = "";
|
||||||
private static String AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED";
|
private static String AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED";
|
||||||
private static CloseableHttpClient httpClient = null;
|
private static CloseableHttpClient httpClient;
|
||||||
|
static {
|
||||||
|
|
||||||
|
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
|
||||||
|
connManager.setMaxTotal(1000);
|
||||||
|
connManager.setDefaultMaxPerRoute(1000);
|
||||||
|
httpClient = HttpClients.custom().setConnectionManager(connManager).setConnectionManagerShared(true).build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 以get方式调用第三方接口
|
* 以get方式调用第三方接口
|
||||||
|
@ -29,7 +43,6 @@ public class HttpClientUtil {
|
||||||
*/
|
*/
|
||||||
public static JSONObject doGet(String url) {
|
public static JSONObject doGet(String url) {
|
||||||
//创建HttpClient对象
|
//创建HttpClient对象
|
||||||
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
||||||
HttpGet httpGet = new HttpGet(url);
|
HttpGet httpGet = new HttpGet(url);
|
||||||
// if (null != tokenString && !tokenString.equals("")) {
|
// if (null != tokenString && !tokenString.equals("")) {
|
||||||
// tokenString = getToken();
|
// tokenString = getToken();
|
||||||
|
@ -56,44 +69,55 @@ public class HttpClientUtil {
|
||||||
* @param json
|
* @param json
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String doPost(String url, JSONObject json) {
|
public static String doPost(String url, String json, String token)
|
||||||
if (null == httpClient) {
|
throws IOException {
|
||||||
httpClient = HttpClientBuilder.create().build();
|
if (StringUtils.isBlank(url)) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
if (null != tokenString && tokenString.equals("")) {
|
httpPost.addHeader("Content-Type", "application/json");
|
||||||
tokenString = getToken();
|
httpPost.addHeader("Accept", "application/json");
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(token)) {
|
||||||
|
httpPost.addHeader("openToken", token);
|
||||||
}
|
}
|
||||||
//api_gateway_auth_token自定义header头,用于token验证使用
|
CloseableHttpResponse response = null;
|
||||||
httpPost.addHeader("api_gateway_auth_token", tokenString);
|
|
||||||
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
|
||||||
try {
|
try {
|
||||||
StringEntity se = new StringEntity(json.toString());
|
|
||||||
se.setContentEncoding("UTF-8");
|
if (!"".equals(json)) {
|
||||||
//发送json数据需要设置contentType
|
// 这里是关键,后面要跟上字符集格式
|
||||||
se.setContentType("application/x-www-form-urlencoded");
|
StringEntity params = new StringEntity(json, "utf-8");
|
||||||
//设置请求参数
|
params.setContentEncoding("utf-8");
|
||||||
httpPost.setEntity(se);
|
// 发送json数据需要设置contentType
|
||||||
HttpResponse response = httpClient.execute(httpPost);
|
params.setContentType("application/json");
|
||||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
httpPost.setEntity(params);
|
||||||
//返回json格式
|
|
||||||
String res = EntityUtils.toString(response.getEntity());
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
response = httpClient.execute(httpPost);
|
||||||
log.error(e.getMessage());
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
if (statusCode != 200) {
|
||||||
|
httpPost.abort();
|
||||||
|
log.error(response.toString());
|
||||||
|
}
|
||||||
|
HttpEntity entity = response.getEntity();
|
||||||
|
String result = null;
|
||||||
|
if (entity != null) {
|
||||||
|
result = EntityUtils.toString(entity, "utf-8");
|
||||||
|
}
|
||||||
|
EntityUtils.consume(entity);
|
||||||
|
return result;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (httpClient != null){
|
if (response != null) {
|
||||||
try {
|
response.close();
|
||||||
httpClient.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取第三方接口的token
|
* 获取第三方接口的token
|
||||||
*/
|
*/
|
||||||
|
@ -128,21 +152,6 @@ public class HttpClientUtil {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试
|
|
||||||
*/
|
|
||||||
public static void test(String telephone) {
|
|
||||||
|
|
||||||
JSONObject object = new JSONObject();
|
|
||||||
object.put("telephone", telephone);
|
|
||||||
|
|
||||||
//首先获取token
|
|
||||||
tokenString = getToken();
|
|
||||||
String response = doPost("http://localhost/searchUrl", object);
|
|
||||||
//如果返回的结果是list形式的,需要使用JSONObject.parseArray转换
|
|
||||||
//List<Result> list = JSONObject.parseArray(response, Result.class);
|
|
||||||
System.out.println(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.aiit.xiuos.Utils.MyUtils;
|
||||||
import com.aiit.xiuos.Utils.ResultRespons;
|
import com.aiit.xiuos.Utils.ResultRespons;
|
||||||
import com.aiit.xiuos.model.UserInfo;
|
import com.aiit.xiuos.model.UserInfo;
|
||||||
import com.aiit.xiuos.service.UserInfoService;
|
import com.aiit.xiuos.service.UserInfoService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
@ -13,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
@Slf4j
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserInfoService userInfoService;
|
private UserInfoService userInfoService;
|
||||||
|
@ -24,10 +25,10 @@ public class LoginController {
|
||||||
if(null!=user){
|
if(null!=user){
|
||||||
HttpSession session = request.getSession();
|
HttpSession session = request.getSession();
|
||||||
session.setAttribute("user",user);//session存用户
|
session.setAttribute("user",user);//session存用户
|
||||||
System.out.println("session======="+session.getId());
|
log.info("session======="+session.getId());
|
||||||
String ip = MyUtils.getIp(request);
|
String ip = MyUtils.getIp(request);
|
||||||
userInfoService.updateLoginInfo(MyUtils.getTime(),ip,user.getId());
|
userInfoService.updateLoginInfo(MyUtils.getTime(),ip,user.getId());
|
||||||
System.out.println("ip++++++++===="+ip);
|
log.info("ip++++++++===="+ip);
|
||||||
return new ResultRespons(Constant.SUCCESS_CODE,"登录成功");
|
return new ResultRespons(Constant.SUCCESS_CODE,"登录成功");
|
||||||
}
|
}
|
||||||
return new ResultRespons(Constant.ERROR_CODE,"登录失败,用户名或密码有误");
|
return new ResultRespons(Constant.ERROR_CODE,"登录失败,用户名或密码有误");
|
||||||
|
|
|
@ -8,11 +8,10 @@ import com.aiit.xiuos.model.VO.ProtocolProductVo;
|
||||||
import com.aiit.xiuos.service.DeviceInfoService;
|
import com.aiit.xiuos.service.DeviceInfoService;
|
||||||
import com.aiit.xiuos.service.ProtocolService;
|
import com.aiit.xiuos.service.ProtocolService;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
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.apache.tomcat.util.http.fileupload.IOUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import sun.nio.ch.IOUtil;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -22,7 +21,7 @@ import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/protocolProduct")
|
@RequestMapping("/protocolProduct")
|
||||||
public class ProtocolProductInfoController {
|
public class ProtocolProductInfoController {
|
||||||
|
@ -116,7 +115,7 @@ public class ProtocolProductInfoController {
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
return new ResultRespons(Constant.ERROR_CODE, "导出csv成功!");
|
return new ResultRespons(Constant.ERROR_CODE, "导出csv成功!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.aiit.xiuos.dao.mappers;
|
package com.aiit.xiuos.dao.mappers;
|
||||||
|
|
||||||
import com.aiit.xiuos.model.QjdqElectric;
|
import com.aiit.xiuos.model.QjdqElectric;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
public interface QjdqElectricMapper {
|
public interface QjdqElectricMapper {
|
||||||
int deleteByPrimaryKey(Integer id);
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,9 @@ public class ProtocolProductVo {
|
||||||
private JSONObject socketConfig;
|
private JSONObject socketConfig;
|
||||||
|
|
||||||
private String readPeriod;
|
private String readPeriod;
|
||||||
|
private String org;
|
||||||
|
|
||||||
public ProtocolProductVo(String productName, String protocolType, JSONArray readItemList, Date updatetime, String deviceId, String deviceName, JSONObject socketConfig, String readPeriod) {
|
public ProtocolProductVo(String productName, String protocolType, JSONArray readItemList, Date updatetime, String deviceId, String deviceName, JSONObject socketConfig, String readPeriod,String org) {
|
||||||
this.productName = productName;
|
this.productName = productName;
|
||||||
this.protocolType = protocolType;
|
this.protocolType = protocolType;
|
||||||
this.readItemList = readItemList;
|
this.readItemList = readItemList;
|
||||||
|
@ -38,6 +39,7 @@ public class ProtocolProductVo {
|
||||||
this.deviceName = deviceName;
|
this.deviceName = deviceName;
|
||||||
this.socketConfig = socketConfig;
|
this.socketConfig = socketConfig;
|
||||||
this.readPeriod = readPeriod;
|
this.readPeriod = readPeriod;
|
||||||
|
this.org =org;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProtocolProductVo(){
|
public ProtocolProductVo(){
|
||||||
|
@ -54,6 +56,7 @@ public class ProtocolProductVo {
|
||||||
protocolProductInfo.setSocketConfig(protocolProductVo.getSocketConfig().toJSONString());
|
protocolProductInfo.setSocketConfig(protocolProductVo.getSocketConfig().toJSONString());
|
||||||
protocolProductInfo.setReadPeriod(protocolProductVo.getReadPeriod());
|
protocolProductInfo.setReadPeriod(protocolProductVo.getReadPeriod());
|
||||||
protocolProductInfo.setUpdatetime(MyUtils.getDateTime());
|
protocolProductInfo.setUpdatetime(MyUtils.getDateTime());
|
||||||
|
protocolProductInfo.setOrg(protocolProductVo.getOrg());
|
||||||
return protocolProductInfo;
|
return protocolProductInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +70,7 @@ public class ProtocolProductVo {
|
||||||
protocolProductVo.setUpdatetime(protocolProductInfo.getUpdatetime());
|
protocolProductVo.setUpdatetime(protocolProductInfo.getUpdatetime());
|
||||||
protocolProductVo.setSocketConfig((JSONObject) JSONObject.parse(protocolProductInfo.getSocketConfig()));
|
protocolProductVo.setSocketConfig((JSONObject) JSONObject.parse(protocolProductInfo.getSocketConfig()));
|
||||||
protocolProductVo.setReadItemList((JSONArray)JSONArray.parse(protocolProductInfo.getReadItemList()));
|
protocolProductVo.setReadItemList((JSONArray)JSONArray.parse(protocolProductInfo.getReadItemList()));
|
||||||
|
protocolProductVo.setOrg(protocolProductInfo.getOrg());
|
||||||
return protocolProductVo;
|
return protocolProductVo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,73 @@
|
||||||
package com.aiit.xiuos.redis;
|
package com.aiit.xiuos.redis;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.*;
|
||||||
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
public class RedisConfig {
|
|
||||||
|
/**
|
||||||
|
* Redis配置
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisConnectionFactory factory;
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate() {
|
||||||
|
// 创建一个模板类
|
||||||
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
|
// 设置key的序列化器
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
|
||||||
|
// 设置value的序列化器
|
||||||
|
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
|
||||||
|
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
|
||||||
|
ObjectMapper om = new ObjectMapper();
|
||||||
|
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
|
||||||
|
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||||
|
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
|
||||||
|
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
|
||||||
|
jacksonSeial.setObjectMapper(om);
|
||||||
|
|
||||||
|
redisTemplate.setValueSerializer(jacksonSeial);
|
||||||
|
// 将刚才的redis连接工厂设置到模板类中
|
||||||
|
//spring默认帮我们读取application.properties文件并且注册了一个factorybean
|
||||||
|
redisTemplate.setConnectionFactory(factory);
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) {
|
||||||
|
return redisTemplate.opsForValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
return redisTemplate.opsForZSet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,191 @@
|
||||||
package com.aiit.xiuos.redis;
|
package com.aiit.xiuos.redis;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.*;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class RedisUtil {
|
public class RedisUtil {
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
@Resource(name="redisTemplate")
|
||||||
|
private ValueOperations<String, String> valueOperations;
|
||||||
|
@Resource(name="redisTemplate")
|
||||||
|
private HashOperations<String, String, Object> hashOperations;
|
||||||
|
@Resource(name="redisTemplate")
|
||||||
|
private ListOperations<String, Object> listOperations;
|
||||||
|
@Resource(name="redisTemplate")
|
||||||
|
private SetOperations<String, Object> setOperations;
|
||||||
|
@Resource(name="redisTemplate")
|
||||||
|
private ZSetOperations<String, Object> zSetOperations;
|
||||||
|
/** 默认过期时长,单位:秒 */
|
||||||
|
public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
|
||||||
|
/** 不设置过期时长 */
|
||||||
|
public final static long NOT_EXPIRE = -1;
|
||||||
|
|
||||||
|
public void set(String key, Object value, long expire){
|
||||||
|
valueOperations.set(key, toJson(value));
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(String key, Object value){
|
||||||
|
set(key, value, DEFAULT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T get(String key, Class<T> clazz, long expire) {
|
||||||
|
String value = valueOperations.get(key);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return value == null ? null : fromJson(value, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T get(String key, Class<T> clazz) {
|
||||||
|
return get(key, clazz, NOT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(String key, long expire) {
|
||||||
|
String value = valueOperations.get(key);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(String key) {
|
||||||
|
return get(key, NOT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(String key) {
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object转成JSON数据
|
||||||
|
*/
|
||||||
|
private String toJson(Object object){
|
||||||
|
if(object instanceof Integer || object instanceof Long || object instanceof Float ||
|
||||||
|
object instanceof Double || object instanceof Boolean || object instanceof String){
|
||||||
|
return String.valueOf(object);
|
||||||
|
}
|
||||||
|
return JSON.toJSONString(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON数据,转成Object
|
||||||
|
*/
|
||||||
|
private <T> T fromJson(String json, Class<T> clazz){
|
||||||
|
return JSON.parseObject(json, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* listOperations使用
|
||||||
|
*/
|
||||||
|
public void lset(String key, List<Object> list, long expire){
|
||||||
|
listOperations.leftPush(key,list);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lset(String key, List<Object> list){
|
||||||
|
lset(key, list, DEFAULT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> lget(String key, long expire) {
|
||||||
|
List<Object> list = (List<Object>)listOperations.leftPop(key);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> lget(String key) {
|
||||||
|
return lget(key, NOT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hashOperations的使用
|
||||||
|
*/
|
||||||
|
public void hset(String key, Map<String,Object> map, long expire){
|
||||||
|
hashOperations.putAll(key,map);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hset(String key,Map<String,Object> map){
|
||||||
|
hset(key, map, DEFAULT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取整个map
|
||||||
|
*/
|
||||||
|
public Map<String,Object> hget(String key, long expire) {
|
||||||
|
Map<String,Object> map = hashOperations.entries(key);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String,Object> hget(String key) {
|
||||||
|
return hget(key, NOT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取map里的一个值
|
||||||
|
*/
|
||||||
|
public Object hget(String key,String mkey, long expire) {
|
||||||
|
Object value = hashOperations.get(key,mkey);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object hget(String key,String mkey) {
|
||||||
|
return hget(key,mkey,NOT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取map里的所有值
|
||||||
|
*/
|
||||||
|
public List<Object> hgetv(String key,long expire) {
|
||||||
|
List<Object> list = hashOperations.values(key);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Object> hgetv(String key) {
|
||||||
|
return hgetv(key,NOT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取map里的所有key
|
||||||
|
*/
|
||||||
|
public Set<String> hgetk(String key,long expire) {
|
||||||
|
Set<String> list = hashOperations.keys(key);
|
||||||
|
if(expire != NOT_EXPIRE){
|
||||||
|
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> hgetk(String key) {
|
||||||
|
return hgetk(key,NOT_EXPIRE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package com.aiit.xiuos.scheduled;
|
package com.aiit.xiuos.scheduled;
|
||||||
|
|
||||||
|
import com.aiit.xiuos.Utils.DingUtil;
|
||||||
import com.aiit.xiuos.Utils.EmailUtil;
|
import com.aiit.xiuos.Utils.EmailUtil;
|
||||||
import com.aiit.xiuos.Utils.MyUtils;
|
import com.aiit.xiuos.Utils.MyUtils;
|
||||||
|
import com.aiit.xiuos.socket.QJDQWebSocketServer;
|
||||||
import com.aiit.xiuos.tdengine.TDengineJDBCUtil;
|
import com.aiit.xiuos.tdengine.TDengineJDBCUtil;
|
||||||
import com.aiit.xiuos.model.*;
|
import com.aiit.xiuos.model.*;
|
||||||
import com.aiit.xiuos.service.*;
|
import com.aiit.xiuos.service.*;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -33,6 +36,10 @@ public class TaskScheduled {
|
||||||
DeviceInfoService deviceInfoService;
|
DeviceInfoService deviceInfoService;
|
||||||
@Autowired
|
@Autowired
|
||||||
EmailUtil emailUtil;
|
EmailUtil emailUtil;
|
||||||
|
@Autowired
|
||||||
|
QjdqElectricService qjdqElectricService;
|
||||||
|
@Autowired
|
||||||
|
QJDQWebSocketServer qjdqWebSocketServer;
|
||||||
@Scheduled(cron = "0 0 */1 * * ?")//every hour
|
@Scheduled(cron = "0 0 */1 * * ?")//every hour
|
||||||
public void insertAvgDayData() throws ParseException {
|
public void insertAvgDayData() throws ParseException {
|
||||||
AvgDayData avgDayData =new AvgDayData();
|
AvgDayData avgDayData =new AvgDayData();
|
||||||
|
@ -86,14 +93,102 @@ public class TaskScheduled {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
Date date = sdf.parse(MyUtils.getTime());
|
Date date = sdf.parse(MyUtils.getTime());
|
||||||
avgDayData.setDatatime(date);
|
avgDayData.setDatatime(date);
|
||||||
|
|
||||||
avgDayDataService.addAvgDayData(avgDayData);
|
avgDayDataService.addAvgDayData(avgDayData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 */1 8-20 * * ?")//every minute 8-20 clock
|
||||||
|
public void updateQJDQ(){
|
||||||
|
QjdqElectric qjdqElectric =qjdqElectricService.selectElectric(1);
|
||||||
|
ArrayList<BigDecimal> arrayList =new ArrayList<>();
|
||||||
|
QjdqElectric newRecord =new QjdqElectric();
|
||||||
|
newRecord.setId(1);
|
||||||
|
newRecord.setElectric2(qjdqElectric.getElectric2().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric2());
|
||||||
|
newRecord.setElectric3(qjdqElectric.getElectric3().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric3());
|
||||||
|
newRecord.setElectric4(qjdqElectric.getElectric4().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric4());
|
||||||
|
newRecord.setElectric5(qjdqElectric.getElectric5().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric5());
|
||||||
|
newRecord.setElectric6(qjdqElectric.getElectric6().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric6());
|
||||||
|
newRecord.setElectric7(qjdqElectric.getElectric7().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric7());
|
||||||
|
newRecord.setElectric8(qjdqElectric.getElectric8().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric8());
|
||||||
|
newRecord.setElectric9(qjdqElectric.getElectric9().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric9());
|
||||||
|
newRecord.setElectric10(qjdqElectric.getElectric10().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric10());
|
||||||
|
newRecord.setElectric11(qjdqElectric.getElectric11().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric11());
|
||||||
|
newRecord.setElectric12(qjdqElectric.getElectric12().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric12());
|
||||||
|
newRecord.setElectric13(qjdqElectric.getElectric13().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric13());
|
||||||
|
newRecord.setElectric14(qjdqElectric.getElectric14().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric14());
|
||||||
|
newRecord.setElectric15(qjdqElectric.getElectric15().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric15());
|
||||||
|
newRecord.setElectric16(qjdqElectric.getElectric16().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric16());
|
||||||
|
newRecord.setElectric17(qjdqElectric.getElectric17().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric17());
|
||||||
|
newRecord.setElectric18(qjdqElectric.getElectric18().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric18());
|
||||||
|
newRecord.setElectric19(qjdqElectric.getElectric19().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric19());
|
||||||
|
newRecord.setElectric20(qjdqElectric.getElectric20().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric20());
|
||||||
|
newRecord.setElectric21(qjdqElectric.getElectric21().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric21());
|
||||||
|
newRecord.setElectric22(qjdqElectric.getElectric22().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric22());
|
||||||
|
newRecord.setElectric23(qjdqElectric.getElectric23().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric23());
|
||||||
|
newRecord.setElectric24(qjdqElectric.getElectric24().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric24());
|
||||||
|
newRecord.setElectric25(qjdqElectric.getElectric25().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric25());
|
||||||
|
newRecord.setElectric26(qjdqElectric.getElectric26().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric26());
|
||||||
|
newRecord.setElectric27(qjdqElectric.getElectric27().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric27());
|
||||||
|
newRecord.setElectric28(qjdqElectric.getElectric28().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric28());
|
||||||
|
newRecord.setElectric29(qjdqElectric.getElectric29().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric29());
|
||||||
|
newRecord.setElectric30(qjdqElectric.getElectric30().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric30());
|
||||||
|
newRecord.setElectric31(qjdqElectric.getElectric31().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric31());
|
||||||
|
newRecord.setElectric32(qjdqElectric.getElectric32().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric32());
|
||||||
|
newRecord.setElectric33(qjdqElectric.getElectric33().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric33());
|
||||||
|
newRecord.setElectric34(qjdqElectric.getElectric34().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric34());
|
||||||
|
newRecord.setElectric35(qjdqElectric.getElectric35().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric35());
|
||||||
|
newRecord.setElectric36(qjdqElectric.getElectric36().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric36());
|
||||||
|
newRecord.setElectric37(qjdqElectric.getElectric37().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric37());
|
||||||
|
newRecord.setElectric38(qjdqElectric.getElectric38().add(new BigDecimal(Math.random())));
|
||||||
|
arrayList.add(qjdqElectric.getElectric38());
|
||||||
|
newRecord.setElectric39(qjdqElectric.getElectric39().add(new BigDecimal(Math.random())));
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 0 * * ?")//every 0:0:0
|
@Scheduled(cron = "0 0 0 * * ?")//every 0:0:0
|
||||||
public void ExecuteRule() throws Exception {
|
public void ExecuteRule() {
|
||||||
//查询保存的每一条告警规则
|
//查询保存的每一条告警规则
|
||||||
List<AlarmRule> alarmRules =alarmRuleService.selectActive();
|
List<AlarmRule> alarmRules =alarmRuleService.selectActive();
|
||||||
for(int i=0;i<alarmRules.size();i++){
|
for(int i=0;i<alarmRules.size();i++){
|
||||||
|
@ -103,7 +198,7 @@ public class TaskScheduled {
|
||||||
String tdString = "select count(*) from " + deviceNo+" where ";
|
String tdString = "select count(*) from " + deviceNo+" where ";
|
||||||
//拼接每一条规则
|
//拼接每一条规则
|
||||||
for(int j=0;j<jsonArray.size();j++){
|
for(int j=0;j<jsonArray.size();j++){
|
||||||
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
JSONObject jsonObject = jsonArray.getJSONObject(j);
|
||||||
String param = jsonObject.getString("param");
|
String param = jsonObject.getString("param");
|
||||||
String condition = jsonObject.getString("condition");
|
String condition = jsonObject.getString("condition");
|
||||||
int value =jsonObject.getInteger("value");
|
int value =jsonObject.getInteger("value");
|
||||||
|
@ -111,37 +206,40 @@ public class TaskScheduled {
|
||||||
}
|
}
|
||||||
//取前一天数据
|
//取前一天数据
|
||||||
tdString+="ts>now-1d";
|
tdString+="ts>now-1d";
|
||||||
System.out.println("sql+++++++++:"+tdString);
|
log.info("sql+++++++++:"+tdString);
|
||||||
//去Tdengine执行sql
|
//去Tdengine执行sql
|
||||||
int count = TDengineJDBCUtil.getCount(tdString);
|
int count = 0;
|
||||||
if(count<=0) {
|
AlarmInfo alarmInfo = new AlarmInfo();
|
||||||
continue;
|
try {
|
||||||
}else{
|
count = TDengineJDBCUtil.getCount(tdString);
|
||||||
AlarmInfo alarmInfo =new AlarmInfo();
|
if (count <= 0) {
|
||||||
alarmInfo.setDeviceNo(deviceNo);
|
log.info("ruleID" + alarmRule.getId() + "不存在告警数据!!!");
|
||||||
alarmInfo.setAlarmTime(MyUtils.getDateTime());
|
continue;
|
||||||
alarmInfo.setAlarmName(alarmRule.getAlarmName());
|
} else {
|
||||||
String type = deviceInfoService.getTypeByName(deviceNo);
|
alarmInfo.setDeviceNo(deviceNo);
|
||||||
if(null==type) type="未知类型";
|
alarmInfo.setAlarmTime(MyUtils.getDateTime());
|
||||||
alarmInfo.setDeviceType(type);
|
alarmInfo.setAlarmName(alarmRule.getAlarmName());
|
||||||
alarmInfo.setAlarmStatus(1);
|
String type = deviceInfoService.getTypeByName(deviceNo);
|
||||||
alarmInfo.setAlarmLevel(alarmRule.getAlarmLevel());
|
if (null == type) type = "未知类型";
|
||||||
alarmInfo.setOrg(alarmRule.getOrg());
|
alarmInfo.setDeviceType(type);
|
||||||
//保存告警信息。告警级别高的插入,低的因主键冲突可自动排除。
|
alarmInfo.setAlarmStatus(1);
|
||||||
try{
|
alarmInfo.setAlarmLevel(alarmRule.getAlarmLevel());
|
||||||
|
alarmInfo.setOrg(alarmRule.getOrg());
|
||||||
|
//保存告警信息。若已存在,执行更新。
|
||||||
alarmInfoService.addAlarmInfo(alarmInfo);
|
alarmInfoService.addAlarmInfo(alarmInfo);
|
||||||
emailUtil.sendMessage(alarmRule.getNoticeAddress(),"设备告警",alarmRule.getNoticeContent());
|
if (alarmRule.getNoticeType().equals("email")) {
|
||||||
log.info("邮件发送成功");
|
emailUtil.sendMessage(alarmRule.getNoticeAddress(), "设备告警", alarmRule.getNoticeContent());
|
||||||
}catch (Exception e){
|
log.info("邮件发送成功");
|
||||||
log.info(e.getMessage());
|
} else if (alarmRule.getNoticeType().equals("dingRob")) {
|
||||||
|
DingUtil.sendMsg(alarmRule.getNoticeAddress(), alarmRule.getNoticeContent());
|
||||||
|
log.info("钉钉发送成功");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
alarmInfoService.updateAlarmInfo(alarmInfo);
|
||||||
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,9 @@ public class AlarmInfoServiceImpl implements AlarmInfoService {
|
||||||
return alarmInfoMapper.getCount(org);
|
return alarmInfoMapper.getCount(org);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addAlarmInfo(AlarmInfo alarmInfo) {
|
||||||
|
return alarmInfoMapper.insertSelective(alarmInfo);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ServerEndpoint(value = "/websocket/{clientId}")
|
@ServerEndpoint(value = "/websocket/jxsd/{clientId}")
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WebSocketServer {
|
public class WebSocketServer {
|
||||||
|
@ -41,7 +41,6 @@ public class WebSocketServer {
|
||||||
* 连接建立成功调用的方法*/
|
* 连接建立成功调用的方法*/
|
||||||
@OnOpen
|
@OnOpen
|
||||||
public void onOpen(@PathParam(value = "clientId") String clientId, Session session) {
|
public void onOpen(@PathParam(value = "clientId") String clientId, Session session) {
|
||||||
|
|
||||||
//接收到发送消息的人员编号
|
//接收到发送消息的人员编号
|
||||||
name = clientId;
|
name = clientId;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
@ -49,12 +48,11 @@ public class WebSocketServer {
|
||||||
webSocketSet.put(clientId,this);
|
webSocketSet.put(clientId,this);
|
||||||
/**在线数加1*/
|
/**在线数加1*/
|
||||||
addOnlineCount();
|
addOnlineCount();
|
||||||
System.out.println("有新连接"+clientId+"加入!当前在线人数为" + getOnlineCount());
|
|
||||||
log.info("有新连接"+clientId+"加入!当前在线人数为" + getOnlineCount());
|
log.info("有新连接"+clientId+"加入!当前在线人数为" + getOnlineCount());
|
||||||
try {
|
try {
|
||||||
sendMessage(clientId+"-连接已建立-");
|
sendMessage(clientId+"-连接已建立-");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("IO异常");
|
log.error("IO异常");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +66,6 @@ public class WebSocketServer {
|
||||||
webSocketSet.remove(name);
|
webSocketSet.remove(name);
|
||||||
/** 在线数减1 */
|
/** 在线数减1 */
|
||||||
subOnlineCount();
|
subOnlineCount();
|
||||||
System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
|
|
||||||
log.info("有一连接"+name+"关闭!当前在线人数为" + getOnlineCount());
|
log.info("有一连接"+name+"关闭!当前在线人数为" + getOnlineCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,7 +76,6 @@ public class WebSocketServer {
|
||||||
* @param message 客户端发送过来的消息*/
|
* @param message 客户端发送过来的消息*/
|
||||||
@OnMessage
|
@OnMessage
|
||||||
public void onMessage(String message, Session session) {
|
public void onMessage(String message, Session session) {
|
||||||
System.out.println("来自客户端的消息:" + message);
|
|
||||||
log.info("来自客户端的消息:" + message);
|
log.info("来自客户端的消息:" + message);
|
||||||
try {
|
try {
|
||||||
this.sendMessage("收到!");
|
this.sendMessage("收到!");
|
||||||
|
@ -93,7 +89,7 @@ public class WebSocketServer {
|
||||||
* **/
|
* **/
|
||||||
@OnError
|
@OnError
|
||||||
public void onError(Session session, Throwable error) {
|
public void onError(Session session, Throwable error) {
|
||||||
System.out.println("发生错误");
|
log.error("发生错误");
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +120,7 @@ public class WebSocketServer {
|
||||||
/**
|
/**
|
||||||
* 群发自定义消息
|
* 群发自定义消息
|
||||||
* */
|
* */
|
||||||
public static void sendInfo(String message) throws IOException {
|
public static void sendInfo(String message) {
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<String, WebSocketServer> entry : webSocketSet.entrySet()) {
|
for (Map.Entry<String, WebSocketServer> entry : webSocketSet.entrySet()) {
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
|
|
|
@ -8,7 +8,7 @@ spring:
|
||||||
nama: xiuosiot
|
nama: xiuosiot
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
url: jdbc:postgresql://115.238.53.59:5432/xiuosiot
|
url: jdbc:postgresql://localhost:5432/xiuosiot
|
||||||
username: xiuosiot
|
username: xiuosiot
|
||||||
password: 123456
|
password: 123456
|
||||||
hikari:
|
hikari:
|
||||||
|
@ -20,7 +20,7 @@ spring:
|
||||||
connection-test-query: select 'x'
|
connection-test-query: select 'x'
|
||||||
pool-name: xiuosiots
|
pool-name: xiuosiots
|
||||||
password: 123456
|
password: 123456
|
||||||
jdbc-url: jdbc:postgresql://115.238.53.59:5432/xiuosiot
|
jdbc-url: jdbc:postgresql://localhost:5432/xiuosiot
|
||||||
|
|
||||||
# 发送邮件配置
|
# 发送邮件配置
|
||||||
mail:
|
mail:
|
||||||
|
|
Loading…
Reference in New Issue