|
|
@@ -1,293 +0,0 @@
|
|
|
-package com.yunfeiyun.agmp.iot.common.constant.device;
|
|
|
-
|
|
|
-import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.yunfeiyun.agmp.common.enums.RedisCacheKey;
|
|
|
-import com.yunfeiyun.agmp.common.framework.manager.RedisCacheManager;
|
|
|
-import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
-import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
-import com.yunfeiyun.agmp.common.utils.spring.SpringUtils;
|
|
|
-import com.yunfeiyun.agmp.iot.common.constant.device.xph.XphRedisUtil;
|
|
|
-import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
-import com.yunfeiyun.agmp.iot.common.domain.*;
|
|
|
-import com.yunfeiyun.agmp.iot.common.enums.YfqxzEnumFactor;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-public class ElementFactorUtil {
|
|
|
- private static Map<String, Integer> getEnumCounterMap(List<QxzDataDto> dataList){
|
|
|
- Map<String, Integer> eNumCounterMap = new HashMap<>();
|
|
|
- for (QxzDataDto dataitem : dataList) {
|
|
|
- String eNum = dataitem.getENum();
|
|
|
- eNumCounterMap.put(eNum, eNumCounterMap.getOrDefault(eNum, 0) + 1);
|
|
|
- }
|
|
|
- return eNumCounterMap;
|
|
|
- }
|
|
|
- public static Map<String, IotDevicefactor> getDevicefactorMap(List<IotDevicefactor> factorList){
|
|
|
- Map<String, IotDevicefactor> devicefactorMap = new HashMap<>();
|
|
|
- for (IotDevicefactor iotDevicefactor : factorList) {
|
|
|
-// String dfCode = iotDevicefactor.getDfCode();
|
|
|
-// String dfName = iotDevicefactor.getDfName();
|
|
|
-// String key = "";
|
|
|
-// if (StringUtils.isNotEmpty(dfCode)) {
|
|
|
-// key += dfCode;
|
|
|
-// }
|
|
|
-// if (StringUtils.isNotEmpty(dfName)) {
|
|
|
-// key += dfName;
|
|
|
-// }
|
|
|
- String key = iotDevicefactor.getDfAddress();
|
|
|
- devicefactorMap.put(key, iotDevicefactor);
|
|
|
- }
|
|
|
- return devicefactorMap;
|
|
|
- }
|
|
|
-
|
|
|
- public static String getAddress(String eName, String eKey){
|
|
|
- return eName + "-" + eKey;
|
|
|
- }
|
|
|
-
|
|
|
- private static IotXphhttpeleconfig getXphHttpEleNum(String eNum){
|
|
|
- RedisCacheManager redisCacheManager = SpringUtils.getBean("redisCacheManager");
|
|
|
- String redisKey = XphRedisUtil.eleConfigKey;
|
|
|
- Map<String, IotXphhttpeleconfig> configMap = redisCacheManager.getCacheObject(RedisCacheKey.IOT_XPH_HTTP_DATA, redisKey);
|
|
|
- IotXphhttpeleconfig iotXphhttpeleconfig = null;
|
|
|
- if(configMap.containsKey(eNum)){
|
|
|
- iotXphhttpeleconfig = configMap.get(eNum);
|
|
|
- }
|
|
|
- return iotXphhttpeleconfig;
|
|
|
- }
|
|
|
-
|
|
|
- public static Map<String, String> getXphHttpEleNameMap(IotDevice iotDeviceResVo){
|
|
|
- String devtypeBid = iotDeviceResVo.getDevtypeBid();
|
|
|
- String devCode = iotDeviceResVo.getDevCode();
|
|
|
-
|
|
|
- List<JSONObject> deviceList = XphRedisUtil.getDeviceList(devtypeBid);
|
|
|
-
|
|
|
- Map<String, Map<String, String>> eleNameMap = new HashMap<>();
|
|
|
- if(deviceList == null || deviceList.isEmpty()){
|
|
|
- ;
|
|
|
- }else{
|
|
|
- for(JSONObject jsonObject: deviceList){
|
|
|
- Map<String, String> e = new HashMap<>();
|
|
|
- String facId = jsonObject.getString("facId");
|
|
|
- String eleName = jsonObject.getString("eleName");
|
|
|
- String[] eleNameArrays = eleName.split("/");
|
|
|
- for(int i=0; i<eleNameArrays.length; i++){
|
|
|
- String eKey = "e" + (i+1);
|
|
|
- String eName = eleNameArrays[i].trim();
|
|
|
- if(eName.equals("-")){
|
|
|
- continue;
|
|
|
- }
|
|
|
- e.put(eKey, eName);
|
|
|
- }
|
|
|
- if(!e.isEmpty()){
|
|
|
- eleNameMap.put(facId, e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return eleNameMap.getOrDefault(devCode, new HashMap<String, String>());
|
|
|
- }
|
|
|
-
|
|
|
- private static IotDevicefactor setYfDisplayname(IotQxzDataListRseVo resVo, Map<String, IotDevicefactor> devicefactorMap){
|
|
|
- IotDevicefactor iotDevicefactor = null;
|
|
|
- /* 新浦会使用的是云飞气象站要素 */
|
|
|
- YfqxzEnumFactor findEnum = YfqxzEnumFactor.findEnumByCode(resVo.getFactorCode());
|
|
|
- if (findEnum != null) {
|
|
|
- resVo.setFactorName(findEnum.getName());
|
|
|
- resVo.setFactorUnit(findEnum.getUnit());
|
|
|
- /* 转换成通用要素 */
|
|
|
-// EnumCommonDataFactor commonDataFactor = XphEnumFactor.toCommonFactor(findEnum);
|
|
|
-// if (commonDataFactor != null) {
|
|
|
-// resVo.setFactorCode(commonDataFactor.getCode());
|
|
|
-// resVo.setFactorName(commonDataFactor.getName());
|
|
|
-// resVo.setFactorUnit(commonDataFactor.getUnit());
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- /* 设置自定义要素名称 */
|
|
|
-// String dfCode = resVo.getFactorCode();
|
|
|
-// String dfName = resVo.getAddress();
|
|
|
-// String key = "";
|
|
|
-// if (StringUtils.isNotEmpty(dfCode)) {
|
|
|
-// key += dfCode;
|
|
|
-// }
|
|
|
-// if (StringUtils.isNotEmpty(dfName)) {
|
|
|
-// key += dfName;
|
|
|
-// }
|
|
|
- String key = resVo.getAddress();
|
|
|
- if (devicefactorMap.containsKey(key)) {
|
|
|
- iotDevicefactor = devicefactorMap.get(key);
|
|
|
- resVo.setFactorDisplayname(iotDevicefactor.getDfDisplayname());
|
|
|
- }
|
|
|
- return iotDevicefactor;
|
|
|
- }
|
|
|
-
|
|
|
- private static IotDevicefactor setXphHttpDisplayname(IotQxzDataListRseVo resVo, Map<String, IotDevicefactor> devicefactorMap){
|
|
|
- IotDevicefactor iotDevicefactor = null;
|
|
|
- /* 新浦会使用的是云飞气象站要素 */
|
|
|
- IotXphhttpeleconfig iotXphhttpeleconfig = getXphHttpEleNum(resVo.getFactorCode());
|
|
|
- if (iotXphhttpeleconfig != null) {
|
|
|
- resVo.setFactorName(iotXphhttpeleconfig.getXphEleCname());
|
|
|
- resVo.setFactorUnit(iotXphhttpeleconfig.getXphEleUnit());
|
|
|
- }
|
|
|
-
|
|
|
- /* 设置自定义要素名称 */
|
|
|
- String dfCode = resVo.getFactorCode();
|
|
|
- String dfName = resVo.getAddress();
|
|
|
- String key = "";
|
|
|
- if (StringUtils.isNotEmpty(dfCode)) {
|
|
|
- key += dfCode;
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(dfName)) {
|
|
|
- key += dfName;
|
|
|
- }
|
|
|
- if (devicefactorMap.containsKey(key)) {
|
|
|
- iotDevicefactor = devicefactorMap.get(key);
|
|
|
- resVo.setFactorDisplayname(iotDevicefactor.getDfDisplayname());
|
|
|
- }
|
|
|
- return iotDevicefactor;
|
|
|
- }
|
|
|
-
|
|
|
- public static IotDevicefactor setDisplayname(IotQxzDataListRseVo resVo, Map<String, IotDevicefactor> devicefactorMap, QxzDataDto dataitem, String devtypeBid){
|
|
|
- IotDevicefactor iotDevicefactor = null;
|
|
|
- resVo.setAddress(getAddress(dataitem.getEName(), dataitem.getEKey()));
|
|
|
- if(Objects.equals(devtypeBid, IotDeviceDictConst.TYPE_XPH_WSHJ_JC)
|
|
|
- || Objects.equals(devtypeBid, IotDeviceDictConst.TYPE_XPH_TRSH_CL)
|
|
|
- || Objects.equals(devtypeBid, IotDeviceDictConst.TYPE_XPH_GP_QXZ)
|
|
|
- ){
|
|
|
- iotDevicefactor = setXphHttpDisplayname(resVo, devicefactorMap);
|
|
|
- }else{
|
|
|
- iotDevicefactor = setYfDisplayname(resVo, devicefactorMap);
|
|
|
- }
|
|
|
- return iotDevicefactor;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 取通道信息MAP
|
|
|
- * @param dataList
|
|
|
- * @return
|
|
|
- */
|
|
|
- private static Map<String, List<String>> getEnumAddressMap(List<QxzDataDto> dataList){
|
|
|
- Map<String, List<String>> eNumAddressMap = new HashMap<>();
|
|
|
- for (QxzDataDto dataitem : dataList) {
|
|
|
- String eNum = dataitem.getENum();
|
|
|
- List<String> addressList = eNumAddressMap.getOrDefault(eNum, new ArrayList<>());
|
|
|
- String address = String.join("-", dataitem.getEName(), dataitem.getEKey());
|
|
|
- if(!addressList.contains(address)){
|
|
|
- addressList.add(address);
|
|
|
- }
|
|
|
- eNumAddressMap.put(eNum, addressList);
|
|
|
- }
|
|
|
- return eNumAddressMap;
|
|
|
- }
|
|
|
-
|
|
|
- public static List<IotQxzDataListRseVo> qxzListProcessData(List<QxzDataDto> dataList, List<IotDevicefactor> factorList, IotDevice iotDeviceResVo, boolean isDisable){
|
|
|
- String devtypeBid = iotDeviceResVo.getDevtypeBid();
|
|
|
- Map<String, String> eleNameMap = getXphHttpEleNameMap(iotDeviceResVo);
|
|
|
- Map<String, IotDevicefactor> devicefactorMap = getDevicefactorMap(factorList);
|
|
|
- Map<String, Integer> eNumCounterMap = getEnumCounterMap(dataList);
|
|
|
-
|
|
|
- List<IotQxzDataListRseVo> retList = new ArrayList<>();
|
|
|
- for (QxzDataDto dataitem : dataList) {
|
|
|
- String eNum = dataitem.getENum();
|
|
|
- Integer eNumCount = eNumCounterMap.get(eNum);
|
|
|
-
|
|
|
- IotQxzDataListRseVo iotQxzDataListRseVo = new IotQxzDataListRseVo();
|
|
|
- iotQxzDataListRseVo.setFactorCode(dataitem.getENum());
|
|
|
- iotQxzDataListRseVo.setNumber(dataitem.getEValue());
|
|
|
- if(dataitem.getTime() != null){
|
|
|
- iotQxzDataListRseVo.setTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, dataitem.getTime()));
|
|
|
- }
|
|
|
- iotQxzDataListRseVo.setDevBid(dataitem.getDevBid());
|
|
|
-
|
|
|
- /* 设置要素名称 用于联合唯一 和前端区分显示 */
|
|
|
- IotDevicefactor iotDevicefactor = setDisplayname(iotQxzDataListRseVo, devicefactorMap, dataitem, devtypeBid);
|
|
|
- String dfDisable = "0";
|
|
|
- if(iotDevicefactor != null){
|
|
|
- dfDisable = iotDevicefactor.getDfDisable();
|
|
|
- if(!isDisable && Objects.equals(dfDisable,"1")){
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- iotQxzDataListRseVo.setDfDisable(dfDisable);
|
|
|
-
|
|
|
- if(IotDeviceDictConst.TYPE_XPH_TRSH_CL.equals(devtypeBid)){
|
|
|
- if(!StringUtils.isEmpty(iotQxzDataListRseVo.getFactorName())){
|
|
|
- iotQxzDataListRseVo.setFactorName(iotQxzDataListRseVo.getFactorName().replace("大气", ""));
|
|
|
- }
|
|
|
- if(StringUtils.isEmpty(iotQxzDataListRseVo.getFactorDisplayname())){
|
|
|
- if(eleNameMap.containsKey(dataitem.getEKey())){
|
|
|
- iotQxzDataListRseVo.setFactorDisplayname(eleNameMap.get(dataitem.getEKey()));
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(Objects.equals(devtypeBid, IotDeviceDictConst.TYPE_XPH_GP_QXZ)){
|
|
|
- if(eleNameMap.containsKey(dataitem.getEKey())){
|
|
|
- iotQxzDataListRseVo.setFactorName(eleNameMap.get(dataitem.getEKey()));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!Objects.equals(devtypeBid, IotDeviceDictConst.TYPE_XPH_GP_QXZ) && StringUtils.isEmpty(iotQxzDataListRseVo.getFactorDisplayname())){
|
|
|
- if(eNumCount > 1){
|
|
|
- String dspName = (eNumCount * 10) + "厘米" + iotQxzDataListRseVo.getFactorName();
|
|
|
- iotQxzDataListRseVo.setFactorDisplayname(dspName);
|
|
|
- eNumCounterMap.put(eNum, eNumCount - 1);
|
|
|
- }
|
|
|
- }
|
|
|
- retList.add(iotQxzDataListRseVo);
|
|
|
- }
|
|
|
- return retList;
|
|
|
- }
|
|
|
-
|
|
|
- public static List<IotQxzDataListRseVo> qxzChartProcessData(
|
|
|
- List<QxzDataDto> dataList, List<IotDevicefactor> factorList, IotDevice iotDeviceResVo, boolean isDisable) {
|
|
|
- String devtypeBid = iotDeviceResVo.getDevtypeBid();
|
|
|
- Map<String, Integer> eNumCounterMap = getEnumCounterMap(dataList);
|
|
|
- Map<String, String> eleNameMap = getXphHttpEleNameMap(iotDeviceResVo);
|
|
|
- Map<String, IotDevicefactor> devicefactorMap = getDevicefactorMap(factorList);
|
|
|
-
|
|
|
- List<IotQxzDataListRseVo> retList = new ArrayList<>();
|
|
|
- for (QxzDataDto dataitem : dataList) {
|
|
|
- String eNum = dataitem.getENum();
|
|
|
- Integer eNumCount = eNumCounterMap.get(eNum);
|
|
|
-
|
|
|
- IotQxzDataListRseVo resVo = new IotQxzDataListRseVo();
|
|
|
- resVo.setFactorCode(dataitem.getENum());
|
|
|
- /* 设置要素名称 用于联合唯一 和前端区分显示 */
|
|
|
- IotDevicefactor iotDevicefactor = setDisplayname(resVo, devicefactorMap, dataitem, devtypeBid);
|
|
|
- String dfDisable = "0";
|
|
|
- if(iotDevicefactor != null){
|
|
|
- dfDisable = iotDevicefactor.getDfDisable();
|
|
|
- if(!isDisable && Objects.equals(dfDisable,"1")){
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- resVo.setDfDisable(dfDisable);
|
|
|
-
|
|
|
- resVo.setDatalist(dataitem.getDataList());
|
|
|
- if(IotDeviceDictConst.TYPE_XPH_TRSH_CL.equals(devtypeBid)){
|
|
|
- if(!StringUtils.isEmpty(resVo.getFactorName())){
|
|
|
- resVo.setFactorName(resVo.getFactorName().replace("大气", ""));
|
|
|
- }
|
|
|
- if(StringUtils.isEmpty(resVo.getFactorDisplayname())){
|
|
|
- if(eleNameMap.containsKey(dataitem.getEKey())){
|
|
|
- resVo.setFactorDisplayname(eleNameMap.get(dataitem.getEKey()));
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(Objects.equals(devtypeBid, IotDeviceDictConst.TYPE_XPH_GP_QXZ)){
|
|
|
- if(eleNameMap.containsKey(dataitem.getEKey())){
|
|
|
- resVo.setFactorName(eleNameMap.get(dataitem.getEKey()));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(!Objects.equals(devtypeBid, IotDeviceDictConst.TYPE_XPH_GP_QXZ) && StringUtils.isEmpty(resVo.getFactorDisplayname())){
|
|
|
- if(eNumCount > 1){
|
|
|
- String dspName = (eNumCount * 10) + "厘米" + resVo.getFactorName();
|
|
|
- resVo.setFactorDisplayname(dspName);
|
|
|
- eNumCounterMap.put(eNum, eNumCount - 1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- retList.add(resVo);
|
|
|
- }
|
|
|
- return retList;
|
|
|
- }
|
|
|
-}
|