Commit b6ab5f1a authored by xinglei's avatar xinglei

*)增加kgd启动项目

parent f64706b7
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-module-api</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>amos-boot-module-kgd-api</artifactId>
<properties>
<tyboot.version>1.1.23-SNAPSHOT</tyboot.version>
</properties>
<dependencies>
<dependency>
<groupId>com.yeejoin</groupId>
<artifactId>amos-component-influxdb</artifactId>
<version>1.7.13-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-component-cache</artifactId>
<version>${tyboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.typroject</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- j2cache 二级缓存 -->
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-spring-boot2-starter</artifactId>
<version>2.8.0-release</version>
</dependency>
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-core</artifactId>
<version>2.8.0-release</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.typroject</groupId>
<artifactId>tyboot-component-emq</artifactId>
<version>${tyboot.version}</version>
<exclusions>
<exclusion>
<groupId>org.typroject</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.yeejoin.amos.kgd.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @Author: xl
* @Description:
* @Date: 2023/10/9 18:45
*/
@Component
public class SocketConfig {
private static final Logger log = LoggerFactory.getLogger(SocketConfig.class);
@Value("${amos.system.socket.port}")
private Integer port;
@Value("${amos.system.maas.url}")
private String hostAndPort;
private static final ThreadPoolExecutor threadpool = new ThreadPoolExecutor(15, 15,
10L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@PostConstruct
public void socketStart() {
//直接另起一个线程挂起Socket服务
new Thread(this::socketServer).start();
}
private void socketServer() {
ServerSocket ss = null;
try {
ss = new ServerSocket(port);
log.info("socket端口在: 【{}】中开启并持续监听=====>", port);
while (Boolean.TRUE) {
Socket clientSocket = ss.accept();
//设置流读取的超时时间,这里设置为10s。超时后自动断开连接
clientSocket.setSoTimeout(10000);
// 创建新线程处理连接
log.info("接收到客户端socket: {}", clientSocket.getRemoteSocketAddress());
threadpool.execute(new ClientHandler(clientSocket,hostAndPort));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
package com.yeejoin.amos.kgd.message;
public class Constant {
public static final String REGION = "REALTIME";
public static final String TOKEN = "Token";
public static final String APPKEY = "appKey";
public static final String PRODUCT = "product";
}
package com.yeejoin.amos.kgd.message;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.component.influxdb.InfluxDbConnection;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import com.yeejoin.amos.kgd.message.model.MessageModel;
import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
@Component
public class IOTPropertyMessageAction extends EmqxListener{
private InfluxDbConnection influxDbConnection;
private InfluxdbUtil influxdbUtil;
private CacheChannel cacheChannel;
public static final int threadNum = 5;
ExecutorService service = Executors.newFixedThreadPool(threadNum);
private static final BlockingQueue<MessageModel> blockingQueue = new LinkedBlockingQueue<MessageModel>();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
public IOTPropertyMessageAction(InfluxDbConnection influxDbConnection, InfluxdbUtil influxdbUtil, CacheChannel cacheChannel) {
this.influxDbConnection = influxDbConnection;
this.cacheChannel = cacheChannel;
this.influxdbUtil = influxdbUtil;
for (int i = 0; i < threadNum; i++) {
service.execute(task_runnable);
}
}
@Override
public void processMessage(String topic,MqttMessage mqttMessage) throws Exception {
MessageModel message = new MessageModel();
message.setPayload(mqttMessage.getPayload());
message.setTableName(topic.replace("/", "").replace("property", ""));
blockingQueue.add(message);
}
Runnable task_runnable = new Runnable() {
public void run() {
while (true) {
try {
MessageModel mqttMessage = blockingQueue.take();
String jsonStr = new String(mqttMessage.getPayload());
String tableName = mqttMessage.getTableName();
if ("iotlogs".contains(tableName)) {
continue;
}
Map<String, String> tagsMap = new HashMap<>();
tagsMap.put("iotCode", tableName);
Map<String, Object> fieldsMap = JSON.parseObject(jsonStr, Map.class);
String sql = "show field keys from " + tableName;
try {
List<Map<String, Object>> list = influxdbUtil.query(sql);
Map<String, Object> fieldsTempMap = new HashMap<>();
for (Map<String, Object> field : list) {
if (fieldsTempMap.containsKey(field.get("fieldKey").toString())) {
continue;
}
fieldsTempMap.put(field.get("fieldKey").toString(), field.get("fieldType").toString());
if (fieldsMap.containsKey(field.get("fieldKey"))) {
if ("integer".equals(field.get("fieldType").toString())) {
fieldsMap.put(field.get("fieldKey").toString(),
Integer.valueOf(fieldsMap.get(field.get("fieldKey")).toString()));
} else if ("float".equals(field.get("fieldType").toString())) {
fieldsMap.put(field.get("fieldKey").toString(),
Float.valueOf(fieldsMap.get(field.get("fieldKey")).toString()));
} else if ("double".equals(field.get("fieldType").toString())) {
fieldsMap.put(field.get("fieldKey").toString(),
Double.valueOf(fieldsMap.get(field.get("fieldKey")).toString()));
}
else {
if ("true".equals(fieldsMap.get(field.get("fieldKey")).toString().toLowerCase()) ||
"false".equals(fieldsMap.get(field.get("fieldKey")).toString().toLowerCase())) {
fieldsMap.put(field.get("fieldKey").toString(), Boolean.valueOf(fieldsMap.get(field.get("fieldKey")).toString()) ? 1 : 0);
} else {
fieldsMap.put(field.get("fieldKey").toString(),
fieldsMap.get(field.get("fieldKey")).toString());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
fieldsMap.put("createdTime", simpleDateFormat.format(new Date()));
influxDbConnection.insert(tableName, tagsMap, fieldsMap);
CacheObject cacheObject = cacheChannel.get(Constant.REGION, tableName);
if (cacheObject.getValue() == null) {
cacheChannel.set(Constant.REGION, tableName, fieldsMap);
} else {
HashMap<String, Object> cacheData = (HashMap<String, Object>) cacheObject.getValue();
cacheData.putAll(fieldsMap);
cacheChannel.set(Constant.REGION, tableName, cacheData);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
}
package com.yeejoin.amos.kgd.message;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqxListener;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.component.influxdb.InfluxDbConnection;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import com.yeejoin.amos.kgd.message.model.MessageModel;
import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
@Component
public class MaasMessageAction extends EmqxListener{
private InfluxDbConnection influxDbConnection;
private InfluxdbUtil influxdbUtil;
private CacheChannel cacheChannel;
public static final int threadNum = 5;
ExecutorService service = Executors.newFixedThreadPool(threadNum);
private static final BlockingQueue<MessageModel> blockingQueue = new LinkedBlockingQueue<MessageModel>();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
public MaasMessageAction(InfluxDbConnection influxDbConnection, InfluxdbUtil influxdbUtil, CacheChannel cacheChannel) {
this.influxDbConnection = influxDbConnection;
this.cacheChannel = cacheChannel;
this.influxdbUtil = influxdbUtil;
for (int i = 0; i < threadNum; i++) {
service.execute(task_runnable);
}
}
@Override
public void processMessage(String topic,MqttMessage mqttMessage) throws Exception {
MessageModel message = new MessageModel();
message.setPayload(mqttMessage.getPayload());
message.setTableName(topic.replace("/", ""));
blockingQueue.add(message);
}
Runnable task_runnable = new Runnable() {
public void run() {
while (true) {
try {
MessageModel mqttMessage = blockingQueue.take();
String jsonStr = new String(mqttMessage.getPayload());
JSONObject data = JSONObject.parseObject(jsonStr);
String tableName = mqttMessage.getTableName();
Map<String, String> tagsMap = new HashMap<>();
Map<String, Object> fieldsMap = JSONObject.toJavaObject(data, HashMap.class);
String sql = "show field keys from " + tableName;
try {
List<Map<String, Object>> list = influxdbUtil.query(sql);
Map<String, Object> fieldsTempMap = new HashMap<>();
for (Map<String, Object> field : list) {
if (fieldsTempMap.containsKey(field.get("fieldKey").toString())) {
continue;
}
fieldsTempMap.put(field.get("fieldKey").toString(), field.get("fieldType").toString());
if (fieldsMap.containsKey(field.get("fieldKey"))) {
if ("integer".equals(field.get("fieldType").toString())) {
fieldsMap.put(field.get("fieldKey").toString(),
Integer.valueOf(fieldsMap.get(field.get("fieldKey")).toString()));
} else if ("float".equals(field.get("fieldType").toString())) {
fieldsMap.put(field.get("fieldKey").toString(),
Float.valueOf(fieldsMap.get(field.get("fieldKey")).toString()));
} else if ("double".equals(field.get("fieldType").toString())) {
fieldsMap.put(field.get("fieldKey").toString(),
Double.valueOf(fieldsMap.get(field.get("fieldKey")).toString()));
} else {
fieldsMap.put(field.get("fieldKey").toString(),
fieldsMap.get(field.get("fieldKey")).toString());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
fieldsMap.put("createdTime", simpleDateFormat.format(new Date()));
influxDbConnection.insert(tableName, tagsMap, fieldsMap);
CacheObject cacheObject = cacheChannel.get(Constant.REGION, tableName);
if (cacheObject.getValue() == null) {
cacheChannel.set(Constant.REGION, tableName, fieldsMap);
} else {
HashMap<String, Object> cacheData = (HashMap<String, Object>) cacheObject.getValue();
cacheData.putAll(fieldsMap);
cacheChannel.set(Constant.REGION, tableName, cacheData);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
}
package com.yeejoin.amos.kgd.message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.typroject.tyboot.component.emq.EmqKeeper;
@Configuration
public class MessageConfig implements ApplicationListener<ApplicationReadyEvent>{
@Autowired
private EmqKeeper emqKeeper;
@Autowired
IOTPropertyMessageAction propertyMessageAction;
@Autowired
MaasMessageAction maasMessageAction;
@Value("spring.application.name")
private String serviceName;
public static final Integer DEFAULT_QOS = 2;
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
try {
emqKeeper.subscript(Topic.IOT_PROPERTY_MESSAGE.getShareTopicStr(serviceName), DEFAULT_QOS, propertyMessageAction);
emqKeeper.subscript(Topic.MAAS_CALCULATION_RESULTS.getShareTopicStr(serviceName), DEFAULT_QOS, maasMessageAction);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.yeejoin.amos.kgd.message;
public enum Topic {
MAAS_CALCULATION_RESULTS("maas/calculation/result"),
IOT_PROPERTY_MESSAGE("+/+/property"),
IOT_SHADOW_MESSAGE("+/+/shadow");
private String topicStr;
Topic(String topicStr) {
this.topicStr = topicStr;
}
public String getTopicStr() {
return topicStr;
}
public String getShareTopicStr(String groupName) {
String shareTopicStr = "$share/" + groupName.trim() + "/" + getTopicStr();
return shareTopicStr;
}
}
package com.yeejoin.amos.kgd.message.model;
import lombok.Data;
@Data
public class MessageModel {
private String tableName;
private byte[] payload;
}
package com.yeejoin.amos.kgd.service;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import com.yeejoin.amos.component.feign.model.Page;
import com.yeejoin.amos.component.influxdb.InfluxDbConnection;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import com.yeejoin.amos.kgd.message.Constant;
import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
@Component
public class LiveDataService {
private final Logger logger = LogManager.getLogger(LiveDataService.class);
@Autowired
private InfluxdbUtil influxdbUtil;
@Autowired
InfluxDbConnection influxDbConnection;
@Autowired
private CacheChannel cacheChannel;
public static final String SPACE = " ";
public static final String ASTERISK = "*";
public static final String DATE = "time";
public static final String COMMA = ",";
public static final String FROM = "FROM";
public static final String WHERE = "WHERE";
public static final String EQUALSIGN = "=";
public static final String AND = "AND";
public List queryHistoryDataForList(String tableName, String timeStart, String timeEnd, String fieldKeys, Map<String, Object> requestParams) {
StringBuffer sqlSb = new StringBuffer();
sqlSb.append("SELECT").append(SPACE);
if (ObjectUtils.isEmpty(fieldKeys)) {
sqlSb.append(SPACE).append(ASTERISK).append(SPACE);
} else {
fieldKeys = fieldKeys + ", createdTime ";
sqlSb.append(SPACE).append(fieldKeys).append(SPACE);
}
sqlSb.append(SPACE).append(FROM).append(SPACE);
sqlSb.append(tableName);
if (!ObjectUtils.isEmpty(requestParams)) {
sqlSb.append(SPACE).append(WHERE).append(SPACE);
sqlSb.append(DATE).append(">=").append("'").append(timeStart).append("'");
sqlSb.append(AND).append(DATE).append("<=").append("'").append(timeEnd).append("'");
Set<String> keys = requestParams.keySet();
StringBuffer whereSb = new StringBuffer();
for (String key : keys) {
whereSb.append(AND).append(SPACE).append(key).append(SPACE).append(EQUALSIGN).append(requestParams.get(key)).append(SPACE);
}
sqlSb.append(whereSb.toString());
}
sqlSb.append(SPACE).append("tz('Asia/Shanghai')");
List<Map<String, Object>> list = influxdbUtil.query(sqlSb.toString());
return list;
}
public Page<Map<String, Object>> queryHistoryDataForPage(String tableName, String timeStart, String timeEnd, String fieldKeys, Map<String, Object> requestParams, long current, long size) {
StringBuffer sqlSb = new StringBuffer();
StringBuffer countSb = new StringBuffer();
StringBuffer whereSb = new StringBuffer();
sqlSb.append("SELECT").append(SPACE);
if (ObjectUtils.isEmpty(fieldKeys)) {
sqlSb.append(SPACE).append(ASTERISK).append(SPACE);
} else {
fieldKeys = fieldKeys + ", createdTime ";
sqlSb.append(SPACE).append(fieldKeys).append(SPACE);
}
sqlSb.append(SPACE).append(FROM).append(SPACE);
sqlSb.append(tableName);
if (!ObjectUtils.isEmpty(requestParams)) {
whereSb.append(SPACE).append(WHERE).append(SPACE);
whereSb.append(DATE).append(">=").append("'").append(timeStart).append("'").append(SPACE);
whereSb.append(AND).append(SPACE).append(DATE).append("<=").append("'").append(timeEnd).append("'");
Set<String> keys = requestParams.keySet();
StringBuffer subWhereSb = new StringBuffer();
for (String key : keys) {
subWhereSb.append(AND).append(SPACE).append(key).append(SPACE).append(EQUALSIGN).append(requestParams.get(key)).append(SPACE);
}
whereSb.append(subWhereSb.toString());
}
sqlSb.append(" LIMIT ").append(size).append(" OFFSET ").append((current - 1) * size);
sqlSb.append(whereSb.toString());
sqlSb.append(SPACE).append("tz('Asia/Shanghai')");
countSb.append("SELECT COUNT(createdTime) FROM ").append(tableName);
countSb.append(whereSb.toString());
List<Map<String, Object>> count = influxdbUtil.query(countSb.toString());
List<Map<String, Object>> list = influxdbUtil.query(sqlSb.toString());
Page<Map<String, Object>> page = new Page<Map<String, Object>>();
page.setCurrent(current);
page.setSize(size);
page.setRecords(list);
page.setTotal((Double.valueOf(count.get(0).get("count").toString()).longValue()));
return page;
}
public Map<String, Object> queryrealTimeData(String tableName) {
CacheObject cacheObject = cacheChannel.get(Constant.REGION, tableName);
return (Map<String, Object>) cacheObject.getValue();
}
}
<?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.yeejoin.amos.avic.face.orm.dao.AvicCustomPathMapper">
</mapper>
......@@ -24,8 +24,9 @@
<module>amos-boot-module-maintenance-api</module>
<module>amos-boot-module-supervision-api</module>
<module>amos-boot-module-knowledgebase-api</module>
<module>amos-boot-module-equip-api</module>
<module>amos-boot-module-latentdanger-api</module>
<module>amos-boot-module-equip-api</module>
<module>amos-boot-module-kgd-api</module>
<module>amos-boot-module-ccs-api</module>
</modules>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-module-biz</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>amos-boot-module-kgd-biz</artifactId>
<dependencies>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-module-kgd-api</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.yeejoin.amos.kgd.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.DateTimeUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.kgd.service.LiveDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@RestController
@Api(tags = "数据Api")
@RequestMapping(value = "/data")
public class DataManagerController extends BaseController{
@Autowired
LiveDataService liveDataService;
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "列表查询数据")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ResponseModel query(
@RequestParam(value = "timeStart") String timeStart,
@RequestParam(value = "timeEnd") String timeEnd,
@RequestParam(value = "measurement") String measurement,
@RequestParam(value = "fieldKey", required = false) String fieldKey) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date start = DateTimeUtil.format(timeStart, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
Date end = DateTimeUtil.format(timeEnd, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
String startUTC = df.format(start);
String endUTC = df.format(end);
Map<String, Object> variables = new HashMap<>();
Enumeration<String> keys = request.getParameterNames();
while(keys.hasMoreElements()){
String name = (String)keys.nextElement();
String value = request.getParameter(name);
variables.put(name, value);
}
variables.remove("timeStart");
variables.remove("timeEnd");
variables.remove("measurement");
variables.remove("fieldKey");
return ResponseHelper.buildResponse(liveDataService.queryHistoryDataForList(measurement, startUTC, endUTC, fieldKey, variables));
}
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "分页查询数据")
@RequestMapping(value = "/page", method = RequestMethod.GET)
public ResponseModel page(
@RequestParam(value = "timeStart") String timeStart,
@RequestParam(value = "timeEnd") String timeEnd,
@RequestParam(value = "measurement") String measurement,
@RequestParam(value = "fieldKey", required = false) String fieldKey,
@RequestParam(value = "current") int current,
@RequestParam(value = "size") int size) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date start = DateTimeUtil.format(timeStart, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
Date end = DateTimeUtil.format(timeEnd, DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
String startUTC = df.format(start);
String endUTC = df.format(end);
Map<String, Object> variables = new HashMap<>();
Enumeration<String> keys = request.getParameterNames();
while(keys.hasMoreElements()){
String name = (String)keys.nextElement();
String value = request.getParameter(name);
variables.put(name, value);
}
variables.remove("timeStart");
variables.remove("timeEnd");
variables.remove("measurement");
variables.remove("fieldKey");
variables.remove("current");
variables.remove("size");
return ResponseHelper.buildResponse(liveDataService.queryHistoryDataForPage(measurement, startUTC, endUTC, fieldKey, variables, current, size));
}
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(value = "最新数据")
@RequestMapping(value = "/realTime", method = RequestMethod.GET)
public ResponseModel realTime(
@RequestParam(value = "measurement") String measurement) {
return ResponseHelper.buildResponse(liveDataService.queryrealTimeData(measurement));
}
}
......@@ -53,6 +53,7 @@
<module>amos-boot-module-supervision-biz</module>
<module>amos-boot-module-latentdanger-biz</module>
<module>amos-boot-module-equip-biz</module>
<module>amos-boot-module-kgd-biz</module>
<module>amos-boot-module-ccs-biz</module>
</modules>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-biz-boot</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>amos-boot-system-kgd</artifactId>
<dependencies>
<dependency>
<groupId>com.amosframework.boot</groupId>
<artifactId>amos-boot-module-kgd-biz</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.yeejoin.amos;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.typroject.tyboot.core.restful.exception.GlobalExceptionHandler;
import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
/**
* <pre>
* 服务启动类
* </pre>
*/
@SpringBootApplication
@EnableTransactionManagement
@EnableConfigurationProperties
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.yeejoin"})
@EnableAsync
@MapperScan({"org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.component.*.face.orm.dao*",
"com.yeejoin.amos.boot.module.*.api.mapper", "com.yeejoin.amos.boot.biz.common.dao.mapper",
"com.yeejoin.amos.avic.face.orm.dao*"})
@ComponentScan(basePackages = {"org.typroject", "com.yeejoin"})
public class AmoKGDApplication {
private static final Logger logger = LoggerFactory.getLogger(AmoKGDApplication.class);
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext context = SpringApplication.run(AmoKGDApplication.class, args);
Environment env = context.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
GlobalExceptionHandler.setAlwaysOk(true);
logger.info("\n----------------------------------------------------------\n\t"
+ "Application Amos-Biz-Boot is running! Access URLs:\n\t" + "Swagger文档: \thttp://" + ip + ":" + port
+ path + "/doc.html\n" + "----------------------------------------------------------");
}
}
## DB properties:
spring.datasource.url=jdbc:mysql://172.16.3.101:3306/jd_bearing?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=Yeejoin@2020
## eureka properties:
eureka.instance.hostname=127.0.0.1
eureka.client.serviceUrl.defaultZone=http://admin:a1234560@localhost:10001/eureka/
## redis properties:
spring.redis.database=1
spring.redis.host=localhost
spring.redis.port=6379
spring.redis.password=yeejoin@2020
spring.cache.type=GENERIC
j2cache.open-spring-cache=true
j2cache.cache-clean-mode=passive
j2cache.allow-null-values=true
j2cache.redis-client=lettuce
j2cache.l2-cache-open=true
j2cache.broadcast=net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy
j2cache.L1.provider_class=caffeine
j2cache.L2.provider_class=net.oschina.j2cache.cache.support.redis.SpringRedisProvider
j2cache.L2.config_section=lettuce
j2cache.sync_ttl_to_redis=true
j2cache.default_cache_null_object=false
j2cache.serialization=fst
caffeine.properties=/caffeine.properties
lettuce.mode=single
lettuce.namespace=
lettuce.storage=generic
lettuce.channel=j2cache
lettuce.scheme=redis
lettuce.hosts=${spring.redis.host}:${spring.redis.port}
lettuce.password=${spring.redis.password}
lettuce.database=${spring.redis.database}
lettuce.sentinelMasterId=
lettuce.maxTotal=100
lettuce.maxIdle=10
lettuce.minIdle=10
lettuce.timeout=10000
emqx.clean-session=true
emqx.client-id=${spring.application.name}-${random.int[1024,65536]}
emqx.broker=tcp://localhost:2883
emqx.client-user-name=super
emqx.client-password=a123456
emqx.max-inflight=1000
spring.influx.url=http://localhost:8086
spring.influx.password=Yeejoin@2020
spring.influx.user=root
spring.influx.database=iot_platform
spring.influx.retention_policy=default
spring.influx.retention_policy_time=30d
spring.influx.actions=10000
spring.influx.bufferLimit=20000
knife4j.production=false
knife4j.enable=true
knife4j.basic.enable=true
knife4j.basic.username=admin
knife4j.basic.password=a1234560
management.security.enabled=true
spring.security.user.name=admin
spring.security.user.password=a1234560
\ No newline at end of file
spring.application.name=AMOS-BIZ-KGD-API
server.servlet.context-path=/kgd
server.port=33002
server.uri-encoding=UTF-8
spring.profiles.active=dev
spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
logging.config=classpath:logback-${spring.profiles.active}.xml
## mybatis-plus\u914D\u7F6E\u63A7\u5236\u53F0\u6253\u5370\u5B8C\u6574\u5E26\u53C2\u6570SQL\u8BED\u53E5
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
## DB properties:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=25
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=120000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
##liquibase
spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml
spring.liquibase.enabled=true
## eureka properties:
eureka.client.registry-fetch-interval-seconds=5
eureka.instance.prefer-ip-address=true
eureka.instance.health-check-url-path=/actuator/health
eureka.instance.lease-expiration-duration-in-seconds=10
eureka.instance.lease-renewal-interval-in-seconds=5
eureka.instance.metadata-map.management.context-path=${server.servlet.context-path}/actuator
eureka.instance.status-page-url-path=/actuator/info
eureka.instance.metadata-map.management.api-docs=http://localhost:${server.port}${server.servlet.context-path}/doc.html
## redis properties:
spring.redis.lettuce.pool.max-active=200
spring.redis.lettuce.pool.max-wait=-1
spring.redis.lettuce.pool.max-idle=10
spring.redis.lettuce.pool.min-idle=0
## redis\u5931\u6548\u65F6\u95F4
redis.cache.failure.time=10800
spring.servlet.multipart.maxFileSize=100MB
spring.servlet.multipart.maxRequestSize=100MB
spring.main.allow-bean-definition-overriding=true
spring.http.encoding.charset=utf-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
amos.system.socket.port=7777
#amos.system.maas.url=172.16.3.221:10005
amos.system.maas.url=127.0.0.1:30009
amos.system.user.user-name=kgd_gdd
amos.system.user.password=a1234560
amos.system.user.app-key=AMOS_STUDIO
amos.system.user.product=AMOS_STUDIO_WEB
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
</databaseChangeLog>
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="log" />
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %-50.50logger{50} - %msg [%file:%line] %n" />
<!-- 按照每天生成日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/ccs.log.%d{yyyy-MM-dd}.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>7</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>${LOG_PATTERN}</pattern>
</encoder>
<!--日志文件最大的大小-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>30mb</MaxFileSize>
</triggeringPolicy>
</appender>
<!-- 控制台输出 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<!--myibatis log configure-->
<logger name="com.apache.ibatis" level="DEBUG"/>
<logger name="java.sql.Connection" level="DEBUG"/>
<logger name="java.sql.Statement" level="DEBUG"/>
<logger name="java.sql.PreparedStatement" level="DEBUG"/>
<logger name="com.baomidou.mybatisplus" level="DEBUG"/>
<logger name="org.springframework" level="DEBUG"/>
<logger name="org.typroject" level="DEBUG"/>
<logger name="com.yeejoin" level="DEBUG"/>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
......@@ -302,6 +302,7 @@
<module>amos-boot-core</module>
<module>amos-boot-utils</module>
<module>amos-boot-system-latentdanger</module>
<module>amos-boot-system-kgd</module>
<module>amos-boot-system-ccs</module>
<module>amos-boot-data</module>
</modules>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment