|
@@ -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;
|
|
|
+ }
|
|
|
}
|