瀏覽代碼

1、消耗、产量 重新生成仅从报表获取日数据
2、电数据补全

QuietShadow 2 年之前
父節點
當前提交
04642ddf74

+ 65 - 3
src/main/java/com/steerinfo/ems/Utils/HttpRequestMes.java

@@ -1,5 +1,8 @@
 package com.steerinfo.ems.Utils;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -8,9 +11,6 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.util.Base64;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 public class HttpRequestMes {
 	
 	private static final Logger logger = LoggerFactory.getLogger(HttpRequestMes.class);
@@ -75,4 +75,66 @@ public class HttpRequestMes {
 		}
 		return buffer.toString();
 	}
+	/**
+	 * 数据接口访问
+	 *
+	 * @param requestUrl    接口地址
+	 * @param requestMethod 请求方法
+	 * @param outputStr     参数
+	 * @param auth          认证
+	 * @return
+	 */
+	public static String httpRequest(String requestUrl, String requestMethod, String outputStr,String auth) {
+		StringBuffer buffer = new StringBuffer();
+		HttpURLConnection httpUrlConn = null;
+		try {
+			// 建立连接
+			URL url = new URL(requestUrl);
+			httpUrlConn = (HttpURLConnection) url.openConnection();
+			httpUrlConn.setRequestMethod(requestMethod.toUpperCase());
+			httpUrlConn.setDoOutput(true);
+			httpUrlConn.setDoInput(true);
+			httpUrlConn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
+
+			if(auth != null && !"GET".equalsIgnoreCase(auth)) {
+				String res = new String(Base64.getEncoder().encode(auth.getBytes()));
+				// 设置认证属性
+				httpUrlConn.setRequestProperty("Authorization", "Basic " + res);
+			}
+			if ("GET".equalsIgnoreCase(requestMethod)) {
+				httpUrlConn.connect();
+			}
+			// 当有数据需要提交时
+			if (outputStr != null && !"GET".equalsIgnoreCase(requestMethod)) {
+				OutputStream outputStream = httpUrlConn.getOutputStream();
+				// 注意编码格式,防止中文乱码
+				outputStream.write(outputStr.getBytes("UTF-8"));
+				outputStream.flush();
+				outputStream.close();
+			}
+			// 获取输入流
+			InputStream inputStream = httpUrlConn.getInputStream();
+			InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
+			BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+			// 读取返回结果
+			buffer = new StringBuffer();
+			String str = null;
+			while ((str = bufferedReader.readLine()) != null) {
+				buffer.append(str);
+			}
+			// 释放资源
+			bufferedReader.close();
+			inputStreamReader.close();
+			inputStream.close();
+		} catch (Exception e) {
+			// e.printStackTrace();
+			logger.error("接口访问错误,url:" + requestUrl + ",requestMethod:" + requestMethod + ",outputStr:" + outputStr);
+			logger.error(e.getMessage());
+		} finally{
+			if(httpUrlConn!=null){
+				httpUrlConn.disconnect();
+			}
+		}
+		return buffer.toString();
+	}
 }

+ 23 - 12
src/main/java/com/steerinfo/ems/trmcalpointvalue/controller/TRmCalpointValueController.java

@@ -1,19 +1,18 @@
 package com.steerinfo.ems.trmcalpointvalue.controller;
 
 import com.steerinfo.auth.utils.JwtUtil;
-import com.steerinfo.framework.controller.BaseRESTfulController;
-import com.steerinfo.framework.controller.RESTfulResult;
-import com.steerinfo.framework.service.pagehelper.PageList;
 import com.steerinfo.ems.formula.service.IFormulaService;
 import com.steerinfo.ems.trmcalpoint.mapper.TRmCalpointMapper;
 import com.steerinfo.ems.trmcalpoint.model.TRmCalpoint;
 import com.steerinfo.ems.trmcalpoint.service.ITRmCalpointService;
 import com.steerinfo.ems.trmcalpointvalue.model.TRmCalpointValue;
 import com.steerinfo.ems.trmcalpointvalue.service.ITRmCalpointValueService;
+import com.steerinfo.framework.controller.BaseRESTfulController;
+import com.steerinfo.framework.controller.RESTfulResult;
+import com.steerinfo.framework.service.pagehelper.PageList;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,14 +20,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * TRmCalpointValue RESTful接口:
@@ -503,4 +495,23 @@ public class TRmCalpointValueController extends BaseRESTfulController {
 		tRmCalpointValueService.insetDataForBb();
 		return success();
 	}
+
+	@ApiOperation(value="从电力需求侧补全历史数据", notes="")
+	//@RequiresPermissions("trmcalpointvalue:view")
+	@GetMapping(value = "/resElData")
+	public RESTfulResult resElData(@RequestParam HashMap<String, Object> parmas,String clock, String clocke) {
+		if(parmas.containsKey("itemid") && parmas.get("itemid") != null && !"".equals(parmas.get("itemid").toString())){
+			String itemid = parmas.get("itemid").toString();
+			if(!itemid.startsWith("'")){
+				itemid = "'" + itemid.replaceAll(",", "','").replaceAll(",", "','") + "'";
+			}
+			String message = tRmCalpointValueService.resEData(itemid,clock,clocke);
+			if(message == "") {
+				return  success();
+			} else {
+				return failed(null, message);
+			}
+		}
+		return failed(null, "参数错误!");
+	}
 }

+ 2 - 0
src/main/java/com/steerinfo/ems/trmcalpointvalue/service/ITRmCalpointValueService.java

@@ -105,4 +105,6 @@ public interface ITRmCalpointValueService extends IBaseService<TRmCalpointValue,
     List<TRmCalpointValue>getDataForBb();
     //
     public void  insetDataForBb();
+
+    String resEData(String itemid, String clock, String clocke);
 }

+ 130 - 0
src/main/java/com/steerinfo/ems/trmcalpointvalue/service/impl/TRmCalpointValueServiceImpl.java

@@ -1,7 +1,11 @@
 package com.steerinfo.ems.trmcalpointvalue.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.steerinfo.auth.utils.JwtUtil;
 import com.steerinfo.ems.Utils.DateUtils;
+import com.steerinfo.ems.Utils.HttpRequestMes;
+import com.steerinfo.ems.Utils.StrUtils;
 import com.steerinfo.ems.cordasconfiguration.mapper.CordasConfigurationMapper;
 import com.steerinfo.ems.cordasconfiguration.model.CordasConfiguration;
 import com.steerinfo.ems.emscalpointvalue.mapper.EmsCalpointValueMapper;
@@ -25,6 +29,7 @@ import org.springframework.dao.DataAccessException;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
+import java.awt.print.PrinterException;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -1174,4 +1179,129 @@ public class TRmCalpointValueServiceImpl extends BaseServiceImpl<TRmCalpointValu
 			}
 		});
 	}
+
+	public String resEData(String itemid,String clock, String clock2) {
+		String url = "http://60.223.245.227:19000/collect/data"; // 生产计划数据
+		HashMap <String,Object> parm = new HashMap<>();
+		parm.put("itemid",itemid);
+		parm.put("itemtype","AUTO");
+		parm.put("energytypeid","'E'");
+		//"deviceIds" :[53,54],
+		//"keyNums" : [11,21,31,41],
+		//"token" :"a9c5c9e2-0910-4a50-a272-e1bf36d24064",
+		//"startTime" :"2022-08-01 00:00:00",
+		//"endTime" :"2022-08-01 23:59:59"
+		String message = "";
+		ArrayList<Integer> deviceIds = new ArrayList<>();
+		ArrayList<Integer> keyNums = new ArrayList<>();
+		final String token = "a9c5c9e2-0910-4a50-a272-e1bf36d24064";
+		Integer keyNum = 11,deviceId = 0;
+		List<TRmCalpoint> tRmCalpointList = tRmCalpointMapper.selectLikeByParameters(parm);
+		System.out.println(tRmCalpointList.toString());
+		//按照电表编号重新排序
+		Collections.sort(tRmCalpointList, (o1, o2) -> {
+			//定义比较大小
+			if(o1.getTagIdMap().matches("^[0-9]+[0-9]*$") && o2.getTagIdMap().matches("^[0-9]+[0-9]*$")) {
+				if(Integer.parseInt(o1.getTagIdMap())  > Integer.parseInt(o2.getTagIdMap())) {
+					return 1;
+				} else if(Integer.parseInt(o1.getTagIdMap())  > Integer.parseInt(o2.getTagIdMap())) {
+					return 0;
+				} else {
+					return -1;
+				}
+			} else {
+				return -1;
+			}
+		});
+		System.out.println(tRmCalpointList);
+		if(tRmCalpointList.size()>0) {
+			Map<String, String> map = new HashMap<>();
+			for (TRmCalpoint tRmCalpoint : tRmCalpointList) {
+				deviceId = StrUtils.strToInteger(tRmCalpoint.getTagIdMap());
+				if(deviceId != null && deviceId < 999){
+					if(!deviceIds.contains(deviceId)) {
+						deviceIds.add(deviceId);
+					}
+					switch (tRmCalpoint.getEnergyid()){
+						//正向有功
+						case "E001" : keyNum = 11; break;
+						//反向有功
+						case "E002" : keyNum = 21; break;
+						//正向无功
+						case "E003" : keyNum = 31; break;
+						default: continue;
+					}
+					if(!keyNums.contains(keyNum)) {
+						keyNums.add(keyNum);
+					}
+					map.put(deviceId.toString() + keyNum.toString(),tRmCalpoint.getTagCol());
+				} else {
+					message +=  tRmCalpoint.getItemid() +"瞬时信号id 配置不正确:"+ tRmCalpoint.getTagIdMap();
+					break;
+				}
+			}
+			String inputString = "{\"deviceIds\": " + Arrays.toString(deviceIds.toArray()) + "," +
+					"\"keyNums\" : " + Arrays.toString(keyNums.toArray()) +"," +
+					"\"token\" : \"" + token +"\"," +
+					"\"startTime\" : \"" + clock +" 00:00:00\"," +
+					"\"endTime\" : \"" + clock2 +" 23:59:59\"" +
+					"}";
+			String res = HttpRequestMes.httpRequest(url,"post",inputString,null);
+			JSONObject jo = JSONObject.parseObject(res);
+			boolean reCalData = false;
+			if (jo != null && !jo.isEmpty() && jo.getString("code").equals("A00000")){
+				JSONArray jo2 = (JSONArray)jo.get("data");
+				JSONObject jo3 ,jo4;
+				String tag = "",UpdateSql ="update EMS_E_AI_HOUR_SUM_TAB1_ORG set ",dataDateTime1 = "",dataDateTime2 ="",selectSql = "select ";
+				String sqlCol = "",sqlClock="", sqlVal = "";
+				if (jo2 != null && !jo2.isEmpty() && jo2.size()>0) {
+					for (int i = 0; i < jo2.size(); i++) {
+						jo4 = (JSONObject) jo2.get(i);
+						dataDateTime2 = jo4.get("dataDateTime").toString();
+						tag = map.get(jo4.get("deviceId").toString() + jo4.get("keyNum").toString());
+						if(!dataDateTime2.endsWith("00") ) {
+							jo3 = (JSONObject)jo2.get(i-1);
+							dataDateTime1 = jo3.get("dataDateTime").toString();
+							if(Integer.parseInt(dataDateTime2.substring(dataDateTime2.length()-2)) - Integer.parseInt(dataDateTime1.substring(dataDateTime1.length()-2))!= 1) {
+								return "电力需求侧中存在不连贯数据:数据列=》"+ tag +",瞬时信号ID=》"+jo4.get("deviceId").toString() +
+										",电类型=》" + jo4.get("keyNum").toString() +",时间区间=》" + dataDateTime2 +"—" + dataDateTime1;
+							}
+						} else {
+							selectSql +=  tag + ",";
+							sqlCol = " "+tag + "= case CLOCK ";
+							sqlClock  = "'"+dataDateTime2+"'";
+						}
+						sqlVal += " when '" + dataDateTime2 + "' then " + "'"+jo4.get("value").toString()+"'";
+						sqlClock  += ",'"+dataDateTime2+"'";
+						if(dataDateTime2.endsWith("23") ) {
+							UpdateSql += sqlCol + sqlVal + " end,";
+							sqlVal = "";
+						}
+					}
+					UpdateSql = UpdateSql.substring(0,UpdateSql.length()-1);
+					UpdateSql += " where clock in (" +sqlClock + ")";
+					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+					Calendar c = Calendar.getInstance();
+					try{
+						Date date = sdf.parse(clock);
+						c.setTime(date);
+					}catch (ParseException e) {
+						new PrinterException(e.getMessage());
+					}
+					c.add(Calendar.DATE, 1);//-1.昨天时间 0.当前时间 1.明天时间 *以此类推
+					String time = sdf.format(c.getTime());
+					selectSql =  selectSql.substring(0,selectSql.length()-1) + " from EMS_E_AI_HOUR_SUM_TAB1_ORG where clock='" + time + " 00'";
+					System.out.println(UpdateSql);
+					System.out.println(selectSql);
+				} else {
+					message = "发送请求成功,电力需求侧无数据返回,请检查瞬时信号ID/电类型是否准确!";
+				}
+			} else {
+				message = jo.getString("code") + jo.getString("data");
+			}
+		} else {
+			return "在计量大类:电 中,未找到对应数据!";
+		}
+		return message;
+	}
 }

+ 7 - 5
src/main/java/com/steerinfo/ems/trmworkprocmaterialvalue/controller/TRmWorkprocMaterialValueController.java

@@ -254,11 +254,13 @@ public class TRmWorkprocMaterialValueController extends BaseRESTfulController {
 			TRmWorkprocMaterial t = l.get(i);
 			res = formulaService.reItemVal(t.getItemid(),clock,timegranid,clocke);
 		}
-        //region 2022-07-13 张琰。
-        //根据报表中的产量数据生成
-        //tRmWorkprocMaterialValueService.getReportValue(parmas);
-        tRmWorkprocMaterialValueService.getMaterialValue(parmas);
-        //endregion
+        if("DAY".equals(timegranid)) {
+            //region 2022-07-13 张琰。
+            //根据报表中的产量数据生成
+            //tRmWorkprocMaterialValueService.getReportValue(parmas);
+            tRmWorkprocMaterialValueService.getMaterialValue(parmas);
+            //endregion
+        }
 		if(!res.isEmpty()){
 			return failed(null, res);
 		}

+ 7 - 5
src/main/java/com/steerinfo/ems/trmworkprocproductvalue/controller/TRmWorkprocProductValueController.java

@@ -439,11 +439,13 @@ public class TRmWorkprocProductValueController extends BaseRESTfulController {
 			TRmWorkprocProduct t = l.get(i);
 			res = formulaService.reItemVal(t.getItemid(),clock,timegranid,clocke);
 		}
-        //region 2022-07-13 张琰。
-        //根据报表中的产量数据生成
-        tRmWorkprocProductValueService.getReportValue(parmas);
-        tRmWorkprocProductValueService.getReportProductValue(parmas);
-        //endregion
+        if("DAY".equals(timegranid)) {
+            //region 2022-07-13 张琰。
+            //根据报表中的产量数据生成
+            tRmWorkprocProductValueService.getReportValue(parmas);
+            tRmWorkprocProductValueService.getReportProductValue(parmas);
+            //endregion
+        }
 		if(!res.isEmpty()){
 			return failed(null, res);
 		}