Browse Source

增加fjd数据导出

menglu 3 years ago
parent
commit
d3bca792da

+ 7 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -199,6 +199,13 @@ public class RestApi {
 		return result;
 	}
 
+	@PostMapping(path = { "/fjd_query_history_batch_export", "/zkt-sdk/fjd_query_history_batch_export" }, produces = "application/json;charset=UTF-8")
+	public ResponseEntity<FileSystemResource> fjd_query_history_batch_export(@RequestBody String param, HttpServletResponse response)
+			throws Exception {
+		ResponseEntity<FileSystemResource> fsr = RestUtil.fjd_query_history_batch_export(param, response);
+		return fsr;
+	}
+
 	@PostMapping(path = { "/path_array_history_fjd_query", "/zkt-sdk/path_array_history_fjd_query" }, produces = "application/json;charset=UTF-8")
 	public String path_array_history_fjd_query(@RequestBody String param, HttpServletRequest request) {
 		String result = RestUtil.path_array_history_fjd_query(param);

+ 35 - 19
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestUtil.java

@@ -10,6 +10,10 @@ import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.ResponseEntity;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -33,6 +37,7 @@ import com.persagy.ibms.data.sdk.util.Constant;
 import com.persagy.ibms.data.sdk.util.ControlUtil;
 import com.persagy.ibms.data.sdk.util.DrawUtil;
 import com.persagy.ibms.data.sdk.util.ExeclReadEquipStaticInfoUtil;
+import com.persagy.ibms.data.sdk.util.ExportUtil;
 import com.persagy.ibms.data.sdk.util.HttpClientUtil;
 import com.persagy.ibms.data.sdk.util.RWDAlarmUtil;
 import com.persagy.ibms.data.sdk.util.RepositoryContainer;
@@ -507,26 +512,8 @@ public class RestUtil {
 	public static String fjd_query_history_batch(String param) {
 		JSONObject result = new JSONObject();
 		try {
-			RepositoryImpl Repository = RepositoryContainer.instance;
 			JSONArray parseArray = JSON.parseArray(param);
-			for (int i = 0; i < parseArray.size(); i++) {
-				JSONObject parseObject = parseArray.getJSONObject(i);
-				String objId = parseObject.getString("objId");
-				String code = parseObject.getString("code");
-				String pointString = Repository.info2point.get(objId).get(code);
-				int index_ = pointString.lastIndexOf('-');
-				String meter = pointString.substring(0, index_);
-				int funcid = Integer.parseInt(pointString.substring(index_ + 1));
-				String data_type = parseObject.getString("data_type");
-				String time_period = parseObject.getString("time_period");
-				if (time_period == null) {
-					time_period = "15min";
-				}
-				String time_from = parseObject.getString("time_from");
-				String time_to = parseObject.getString("time_to");
-				JSONArray dataArray = fjd_query_inner(meter, funcid, data_type, time_period, time_from, time_to);
-				parseObject.put("datas", dataArray);
-			}
+			fjd_query_history_batch_fill(parseArray);
 			result.put("Content", parseArray);
 			result.put("Result", "success");
 		} catch (Exception e) {
@@ -540,6 +527,35 @@ public class RestUtil {
 		return result.toJSONString();
 	}
 
+	public static ResponseEntity<FileSystemResource> fjd_query_history_batch_export(String param, HttpServletResponse response) throws Exception {
+		JSONArray parseArray = JSON.parseArray(param);
+		fjd_query_history_batch_fill(parseArray);
+		ResponseEntity<FileSystemResource> fsr = ExportUtil.fjd_export(parseArray);
+		return fsr;
+	}
+
+	public static void fjd_query_history_batch_fill(JSONArray parseArray) throws Exception {
+		RepositoryImpl Repository = RepositoryContainer.instance;
+		for (int i = 0; i < parseArray.size(); i++) {
+			JSONObject parseObject = parseArray.getJSONObject(i);
+			String objId = parseObject.getString("objId");
+			String code = parseObject.getString("code");
+			String pointString = Repository.info2point.get(objId).get(code);
+			int index_ = pointString.lastIndexOf('-');
+			String meter = pointString.substring(0, index_);
+			int funcid = Integer.parseInt(pointString.substring(index_ + 1));
+			String data_type = parseObject.getString("data_type");
+			String time_period = parseObject.getString("time_period");
+			if (time_period == null) {
+				time_period = "15min";
+			}
+			String time_from = parseObject.getString("time_from");
+			String time_to = parseObject.getString("time_to");
+			JSONArray dataArray = fjd_query_inner(meter, funcid, data_type, time_period, time_from, time_to);
+			parseObject.put("datas", dataArray);
+		}
+	}
+
 	public static String fjd_query_history(String meter, int funcid, String data_type, String time_period, String time_from, String time_to) {
 		JSONObject result = new JSONObject();
 		try {

+ 29 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ExportUtil.java

@@ -81,6 +81,35 @@ public class ExportUtil {
 		return ExportUtil.export(new File(filepath));
 	}
 
+	public static ResponseEntity<FileSystemResource> fjd_export(JSONArray parseArray) throws Exception {
+		Map<String, ExcelSheet> sheetMap = new HashMap<String, ExcelSheet>();
+		for (int i = 0; i < parseArray.size(); i++) {
+			JSONObject parseObject = parseArray.getJSONObject(i);
+			String code = parseObject.getString("code");
+			String data_type = parseObject.getString("data_type");
+			JSONArray datas = parseObject.getJSONArray("datas");
+			ExcelSheet sheet = new ExcelSheet();
+			sheet.titleColList.add("time");
+			sheet.titleColList.add("value");
+			for (int ii = 0; ii < datas.size(); ii++) {
+				JSONObject data = datas.getJSONObject(ii);
+				List<String> contentList = new ArrayList<String>();
+				contentList.add(data.getString("data_time"));
+				contentList.add(data.getString("data_value"));
+				sheet.contentListList.add(contentList);
+			}
+			sheetMap.put(code + "-" + data_type, sheet);
+		}
+
+		String filepath = UUID.randomUUID().toString() + ".xlsx";
+		try {
+			ExcelCommonUtil.Write(filepath, sheetMap);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return ExportUtil.export(new File(filepath));
+	}
+
 	public static void alarm_export(JSONObject result, HttpServletResponse response) throws Exception {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS");
 		JSONArray alarm_export_title = FastJsonReaderUtil.Instance()

+ 3 - 1
ibms-data-sdk/src/main/resources/config.xml

@@ -23,9 +23,11 @@
 	<iot_project url="http://192.168.100.33:9909/iot-project/" />
 	<!-- 报警的websocket地址和服务地址 -->
 	<!--
-	<alarm enable="true" websocket="ws://192.168.100.33:9909/webSocketServer" rest="http://192.168.100.33:9909/zkt-alarm/" rest_get="false" />
 	-->
+	<alarm enable="true" websocket="ws://192.168.100.33:9909/webSocketServer" rest="http://192.168.100.33:9909/zkt-alarm/" rest_get="false" />
+	<!--
 	<alarm enable="true" websocket="http://39.102.43.179:9993/webSocketServer" rest="http://39.102.43.179:9993/" rest_get="true" />
+	-->
 
 	<ConfigRelation graphCode="ArchSubset" relCode="Bd2Fl" objFrom="building" objTo="floor" nameInTo="所属建筑" multiplicityTo="1" />
 	<ConfigRelation graphCode="ArchSubset" relCode="Bd2Sp" objFrom="building" objTo="space" nameInTo="所属建筑" multiplicityTo="1" />