package com.ard.work.health.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ard.work.health.client.EquipmentsHealthClient; import com.ard.work.health.client.HealthUtil; import com.ard.work.api.domian.AlertInfoDto; import com.ard.work.health.domain.GetEquipmentAlertInfoParam; import com.ard.work.health.domain.GetFMTrendParam; import com.ard.work.health.domain.GetTrendParam; import com.ard.work.health.service.HealthService; import com.ard.work.utils.soap.ARDSoapUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class HealthServiceImpl implements HealthService { @Value("${health.url}") private String url; @Value("${health.eqHealthUrl}") private String eqUrl; @Value("${health.eqHealthAccount}") private String account; @Value("${health.eqHealthPassword}") private String password; @Value("${health.openClose}") Boolean openClose; /** * 获取设备列表 * * @return JSONObject */ @Override public JSONObject getEquipmentList() { JSONObject jsonRes = new JSONObject(); Map map = new HashMap(); String result = ARDSoapUtil.postSoapResult(url, "GetEquipmentList", map); if ("".equals(result)) { //没有设备信息 return (JSONObject) jsonRes.put("errmsg", "没有设备信息"); } Map mapResult = (Map) JSON.parse((String) result); if ((int) mapResult.get("code") == 200) { jsonRes.put("code", mapResult.get("code")); List> listResult = (List>) JSON.parse((String) mapResult.get("resdata")); for (int i = 0; i < listResult.size(); i++) { Map mapTemp = listResult.get(i); int id = (Integer) mapTemp.get("id"); //主键id jsonRes.put(id + "", mapTemp); } } else { //错误提示 jsonRes.put("errmsg", mapResult.get("errmsg")); jsonRes.put("code", mapResult.get("code")); } return jsonRes; } /** * 根据name获取某个油井测点列表 * * @param equipNumber equipNumber * @return JSONObject */ @Override public JSONObject getMeasureByEquipName(String equipNumber) { JSONObject jsonRes = new JSONObject(); Map map = new HashMap(); String result = ARDSoapUtil.postSoapResult(url, "GetEquipmentList", map); String equipKey = ""; if ("".equals(result)) { return (JSONObject) jsonRes.put("errmsg", "没有设备信息"); } Map mapResult = (Map) JSON.parse((String) result); if ((int) mapResult.get("code") == 200) { jsonRes.put("code", mapResult.get("code")); List> listResult = (List>) JSON.parse((String) mapResult.get("resdata")); for (int i = 0; i < listResult.size(); i++) { Map mapTemp = listResult.get(i); String equipNumberTemp = (String) mapTemp.get("EquipNumber"); //设备名称 if (equipNumberTemp.equals(equipNumber)) { //名称匹配,即为要获取的设备; equipKey = (String) mapTemp.get("EquipKey"); //设备Key } } if ("".equals(equipKey)) { return (JSONObject) jsonRes.put("errmsg", "没有测点信息"); } //获取设备的测点列表 Map hashMap = new HashMap(); hashMap.put("EquipKey", equipKey); String eResult = ARDSoapUtil.postSoapResult(url, "GetMeasureByEquipKey", hashMap); if ("".equals(eResult)) { return (JSONObject) jsonRes.put("errmsg", "没有测点信息"); } Map map1 = (Map) JSON.parse((String) eResult); if ((int) map1.get("code") == 200) { jsonRes.put("code", map1.get("code")); List> list = (List>) JSON.parse((String) map1.get("resdata")); jsonRes.put("listResult", list); } else { //错误提示 jsonRes.put("errmsg", mapResult.get("errmsg")); jsonRes.put("code", mapResult.get("code")); } } else { //错误提示 jsonRes.put("errmsg", mapResult.get("errmsg")); jsonRes.put("code", mapResult.get("code")); } return jsonRes; } /** * 获取某油井一段时间的测量趋势 * * @param getTrendParam getTrendParam * @return JSONObject */ @Override public JSONObject getTrend(GetTrendParam getTrendParam) { Map map = new HashMap(); map.put("MeasureKey", getTrendParam.getMeasureKey()); map.put("StartTime", getTrendParam.getStartTime()); map.put("EndTime", getTrendParam.getEndTime()); JSONObject jsonRes = new JSONObject(); String result = ARDSoapUtil.postSoapResult(url, "GetTrend", map); if ("".equals(result)) { jsonRes.put("msg", "没有测点信息"); jsonRes.put("code", 500); return jsonRes; } Map mapResult = (Map) JSON.parse((String) result); if ((int) mapResult.get("code") == 200) { jsonRes.put("code", mapResult.get("code")); List> listResult = (List>) JSON.parse((String) mapResult.get("resdata")); if (listResult.size() > 0) { for (int i = 0; i < listResult.size(); i++) { Map mapTemp = listResult.get(i); BigDecimal value = (BigDecimal) mapTemp.get("Value"); //数值 String measureStr = (String) mapTemp.get("MeasureDate"); //测量时间 measureStr = measureStr.substring(measureStr.indexOf("(") + 1, measureStr.indexOf(")", 2)); SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String measureDate = f.format(Long.valueOf(measureStr)); mapTemp.put("MeasureDate", measureDate); mapTemp.put("Value", value.setScale(2, BigDecimal.ROUND_HALF_UP)); } jsonRes.put("data", listResult); } else { jsonRes.put("data", new ArrayList<>()); } } else { //错误提示 jsonRes.put("msg", mapResult.get("errmsg")); jsonRes.put("code", mapResult.get("code")); } return jsonRes; } /** * 获取某次测量数据的图谱 * * @param id id * @return JSONObject */ @Override public JSONObject getWaveDataByIndex(String id) { Map map = new HashMap(); map.put("id", id); JSONObject jsonRes = new JSONObject(); String result = ARDSoapUtil.postSoapResult(url, "GetWaveDataByIndex", map); if ("".equals(result)) { jsonRes.put("msg", "没有测点信息"); jsonRes.put("code", 500); return jsonRes; } Map mapResult = (Map) JSON.parse((String) result); if ((int) mapResult.get("code") == 200) { jsonRes.put("code", mapResult.get("code")); List> listResult = (List>) JSON.parse((String) mapResult.get("resdata")); int frequency = (Integer) listResult.get(0).get("Frequency"); //频宽 int lines = (Integer) listResult.get(0).get("Lines");//线数 int measureCycle = (Integer) listResult.get(0).get("MeasureCycle");//采样时间 List waveDataImage = (List) listResult.get(0).get("WaveDataImage");//时域图谱 List FrequencyDataImage = (List) listResult.get(0).get("FrequencyDataImage"); //频域图谱 jsonRes.put("frequency", frequency); jsonRes.put("lines", lines); jsonRes.put("measureCycle", measureCycle); jsonRes.put("waveDataImage", waveDataImage); jsonRes.put("FrequencyDataImage", FrequencyDataImage); } else { //错误提示 jsonRes.put("errmsg", mapResult.get("errmsg")); jsonRes.put("code", mapResult.get("code")); } return jsonRes; } /** * 获取某个测点的最后一次报警信息 * * @param number number * @return JSONObject */ @Override public List getAlertInfo(String number) { List alertInfoLs = new ArrayList<>(); if (!openClose){ return alertInfoLs; } Map map = new HashMap(); map.put("WellNumber", number); String result = ARDSoapUtil.postSoapResult(url, "GetWellAlertInfo", map); if ("".equals(result)) { return null; } Map mapResult = (Map) JSON.parse((String) result); if ((int) mapResult.get("code") == 200) { List> listResult = (List>) JSON.parse((String) mapResult.get("resdata")); for (int i = 0; i < listResult.size(); i++) { AlertInfoDto alDto = new AlertInfoDto(); Map mapTemp = listResult.get(i); alDto.setId((Integer) mapTemp.get("id")); alDto.setPosition((String) mapTemp.get("position")); alDto.setProblem((String) mapTemp.get("problem")); alDto.setSuggestion((String) mapTemp.get("suggestion")); alertInfoLs.add(alDto); } } return alertInfoLs; } /** * 获取某异常问题(失效模式)的趋势 * * @param getFMTrendParam getFMTrendParam * @return JSONObject */ @Override public JSONObject getFMTrend(GetFMTrendParam getFMTrendParam) { Map map = new HashMap(); map.put("id", getFMTrendParam.getId()); map.put("StartTime", getFMTrendParam.getStartTime()); map.put("EndTime", getFMTrendParam.getEndTime()); JSONObject jsonRes = new JSONObject(); String result = ARDSoapUtil.postSoapResult(url, "GetFMTrend", map); if ("".equals(result)) { return (JSONObject) jsonRes.put("errmsg", "没有测点信息"); } Map mapResult = (Map) JSON.parse((String) result); if ((int) mapResult.get("code") == 200) { jsonRes.put("code", mapResult.get("code")); List> listResult = (List>) JSON.parse((String) mapResult.get("resdata")); jsonRes.put("listResult", listResult); for (int i = 0; i < listResult.size(); i++) { Map mapTemp = listResult.get(i); int id = (Integer) mapTemp.get("id"); //主键id String value = (String) mapTemp.get("Value"); //数值 String measureStr = (String) mapTemp.get("MeasureDate"); //测量时间 } } else { //错误提示 jsonRes.put("errmsg", mapResult.get("errmsg")); jsonRes.put("code", mapResult.get("code")); } return jsonRes; } /** * 根据key获取某个油井测点列表 * * @param equipKey equipKey * @return JSONObject */ @Override public JSONObject getMeasureByEquipKey(String equipKey) { JSONObject jsonRes = new JSONObject(); //获取设备的测点列表 Map hashMap = new HashMap(); hashMap.put("EquipKey", equipKey); String eResult = ARDSoapUtil.postSoapResult(url, "GetMeasureByEquipKey", hashMap); if ("".equals(eResult)) { return (JSONObject) jsonRes.put("errmsg", "没有测点信息"); } Map map1 = (Map) JSON.parse((String) eResult); if ((int) map1.get("code") == 200) { jsonRes.put("code", map1.get("code")); List> list = (List>) JSON.parse((String) map1.get("resdata")); jsonRes.put("listResult", list); } return jsonRes; } /** * 获取ID获取点位 * * @param id id * @return JSONObject */ @Override public Map GetPartsAlertLevel(Integer id) { String token = HealthUtil.getKJNToken(eqUrl, account, password); String GetPartsAlertLeveUrl = eqUrl + HealthUtil.R_Z_M_G; Map map = EquipmentsHealthClient.GetPartsAlertLeve(GetPartsAlertLeveUrl, token, id); return map; } /** * 根据ID获取详细说明 * * @param param param * @return JSONObject */ @Override public List> GetEquipmentAlertInfo(GetEquipmentAlertInfoParam param) { Integer id = param.getId(); String key = param.getPosition(); String token = HealthUtil.getKJNToken(eqUrl, account, password); String GetEquipmentAlertInfoUrl = eqUrl + HealthUtil.R_H_V_01; Map map = EquipmentsHealthClient.GetEquipmentAlertInfo(GetEquipmentAlertInfoUrl, token, id); List list = (List) ((Map) map.get("data")).get("rows"); List> rList = new ArrayList<>(); if (list.size() > 0) { for (int i = 0; i < list.size(); i++) { Map listMap = (Map) list.get(i); String position = (String) listMap.get("position"); if (key.equals(position)) { rList.add(listMap); } } } return rList; } /** * 获取油井列表 * * @return JSONObject */ @Override public Map getTreeJsonX() { String token = HealthUtil.getKJNToken(eqUrl, account, password); String GetPartsAlertLeveUrl = eqUrl + HealthUtil.R_H_V_02; Map map = EquipmentsHealthClient.GetTreeJsonX(GetPartsAlertLeveUrl, token); return map; } }