Просмотр исходного кода

新增 获取云飞气象站折线图接口

zhaiyifei 1 год назад
Родитель
Сommit
ee4e1571a8

+ 215 - 0
src/main/java/com/yunfeiyun/agmp/iot/common/constant/device/ElementFactorUtil.java

@@ -0,0 +1,215 @@
+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.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<? extends QxzChartDataDto> dataList){
+        Map<String, Integer> eNumCounterMap = new HashMap<>();
+        for (QxzChartDataDto 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;
+            }
+            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;
+        }
+        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, QxzChartDataDto 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;
+    }
+
+    public static List<IotQxzDataListRseVo> qxzChartProcessData(
+            List<QxzChartDataDto> dataList, List<IotDevicefactor> factorList, IotDevice iotDeviceResVo, boolean isDisable) {
+        String devtypeBid = iotDeviceResVo.getDevtypeBid();
+        String devCode = iotDeviceResVo.getDevCode();
+        Map<String, Integer> eNumCounterMap = getEnumCounterMap(dataList);
+        Map<String, String> eleNameMap = getXphHttpEleNameMap(iotDeviceResVo);
+        Map<String, IotDevicefactor> devicefactorMap = getDevicefactorMap(factorList);
+
+        List<IotQxzDataListRseVo> retList = new ArrayList<>();
+        for (QxzChartDataDto 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;
+    }
+}

+ 0 - 2
src/main/java/com/yunfeiyun/agmp/iot/common/constant/device/yfqxz/YfqxzUtil.java

@@ -155,8 +155,6 @@ public class YfqxzUtil {
                 ret = "hour";
             }
         }
-
-
         return ret;
     }
 

+ 2 - 2
src/main/java/com/yunfeiyun/agmp/iot/common/domain/IotDevicefactor.java

@@ -2,8 +2,6 @@ package com.yunfeiyun.agmp.iot.common.domain;
 
 import com.yunfeiyun.agmp.common.annotation.Excel;
 import lombok.Data;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
 
 /**
  * 设备要素对象 IotDevicefactor
@@ -62,4 +60,6 @@ public class IotDevicefactor extends IotBaseEntity
     /** 是否禁用  0不禁用,1禁用 */
     @Excel(name = "是否禁用")
     private String dfDisable;
+
+    private String tid;
 }

+ 73 - 0
src/main/java/com/yunfeiyun/agmp/iot/common/domain/IotQxzDataListRseVo.java

@@ -0,0 +1,73 @@
+package com.yunfeiyun.agmp.iot.common.domain;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.annotation.Excel;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class IotQxzDataListRseVo {
+    /**
+     * 针对同一要素有一组传感器的情况
+     * 能够区分不同传感器的序号或者标识
+     */
+    public String address;
+
+    /**
+     * 客户ID
+     */
+    public String cId;
+
+    /**
+     * 采集时间 (复制原始值)
+     */
+    public Date datetime;
+
+    /**
+     * 设备ID
+     */
+    public String devBid;
+
+    /**
+     * 是否禁用
+     */
+    public String dfDisable;
+
+    /**
+     * 要素编码
+     */
+    public String factorCode;
+
+    public String factorCustomunit;
+
+    /**
+     * 要素自定义名称
+     */
+    public String factorDisplayname;
+
+    /**
+     * 要素名称
+     */
+    @Excel(name = "要素名称")
+    public String factorName;
+
+    /**
+     * 要素单位
+     */
+    public String factorUnit;
+
+    /**
+     * 要素的值
+     */
+    @Excel(name = "值")
+    public String number;
+
+    /**
+     * 采集时间 (yyyy-MM-dd HH:mm:ss)
+     */
+    public String time;
+
+    public List<JSONObject> datalist;
+}

+ 19 - 0
src/main/java/com/yunfeiyun/agmp/iot/common/domain/QxzChartDataDto.java

@@ -0,0 +1,19 @@
+package com.yunfeiyun.agmp.iot.common.domain;
+
+import com.alibaba.fastjson2.JSONObject;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class QxzChartDataDto {
+    public String eNum;
+
+    public String eName;
+
+    public String eKey;
+
+    public String eValue;
+
+    public List<JSONObject> dataList;
+}

+ 116 - 0
src/main/java/com/yunfeiyun/agmp/iot/common/enums/element/YfQxzElementEnum.java

@@ -0,0 +1,116 @@
+package com.yunfeiyun.agmp.iot.common.enums.element;
+
+import com.yunfeiyun.agmp.iot.common.enums.YfqxzEnumFactor;
+
+public enum YfQxzElementEnum {
+    TYPE1("101","大气温度","℃"),
+    TYPE2("102","大气湿度","%RH"),
+    TYPE3("103","模拟气压","hpa"),
+    TYPE4("104","雨量","mm"),
+    TYPE5("105","简易总辐射","w/㎡"),
+    TYPE6("106","土壤温度","°C"),
+    TYPE6_7("107","土壤湿度","%RH"),
+    TYPE7("108","风速","m/s"),
+    TYPE8("109","风向","°"),
+    TYPE9("110","蒸发","mm"),
+    TYPE10("111","雪量","mm"),
+    TYPE11("112","照度","LUX"),
+    TYPE12("113","日照时数","h"),
+    TYPE13("114","光合","w/㎡"),
+    TYPE14("115","雨量累计","mm"),
+    TYPE15("116","辐射累计","MJ/㎡"),
+    TYPE16("117","有无雨雪",""),
+    TYPE17("118","噪声","分贝"),
+    TYPE18("119","水位","cm"),
+    TYPE19("120","二氧化碳","PPM"),
+    TYPE20("121","曝辐量","cal/cm2"),
+    TYPE25("122","液位","mm"),
+    TYPE26("123","光合有效辐射","W/m2"),
+    TYPE27("124","电压","V"),
+    TYPE28("125","紫外线","w/㎡"),
+    TYPE29("126","粉尘","ug/m3"),
+    TYPE30("127","数字气压","hpa"),
+    TYPE31("128","PH值",""),
+    TYPE32("129","最大风速","m/s"),
+    TYPE33("130","平均风速","m/s"),
+    TYPE34("131","经度","°"),
+    TYPE35("132","纬度","°"),
+    TYPE36("133","海拔高度","m"),
+    TYPE37("134","TBQ总辐射","w/㎡"),
+    TYPE38("135","直接辐射","w/㎡"),
+    TYPE39("136","散射辐射","w/㎡"),
+    TYPE40("138","紫外辐射","w/㎡"),
+    TYPE41("139","贴片温度","°C"),
+    TYPE42("140","露点温度","°C"),
+    TYPE43("141","一氧化碳","PPM"),
+    TYPE44("142","电流","mA"),
+    TYPE45("143","超声波风速","m/s"),
+    TYPE46("144","水温","°C"),
+    TYPE47("145","PM2.5","ug/m³"),
+    TYPE48("146","PM10","ug/m³"),
+    TYPE49("147","PH",""),
+    TYPE50("148","溶解氧","mg/l"),
+    TYPE51("149","氨氮","mg/l"),
+    //TYPE52("150","电导率","mS/cm"),
+    TYPE53("151","浊度","NTU"),
+    TYPE54("152","能见度","m"),
+    TYPE55("153","氨气","ppm"),
+    TYPE56("154","盐分","mg/L"),
+    TYPE57("155","氮","mg/kg"),
+    TYPE58("156","磷","mg/kg"),
+    TYPE59("157","钾","mg/kg"),
+    TYPE60("158","热通量","w/㎡"),
+    TYPE61("159","叶面温度","°C"),
+    TYPE62("160","叶面湿度","%RH"),
+    TYPE63("161","茎秆","cm"),
+    TYPE64("162","负氧离子","个/cm3"),
+    TYPE65("201","土壤水势","KPa"),
+    TYPE66("202","露点温度","°C"),
+    TYPE67("203","PM100","ug/m³"),
+    //TYPE68("208","照度","Lux"),
+    TYPE69("224","信号强度",""),
+    TYPE70("228","水质pH","Lux"),
+    TYPE71("256","悬浮物","mg/L"),
+    TYPE72("257","透明度","NTU"),
+    TYPE73("211","电导率","uS/cm"),
+    TYPE74("220","土壤电导率","uS/cm"),
+    TYPE75("232","二氧化氮","PPM");
+
+
+    private String code;
+    private String name;
+
+    private String unit;
+
+    private YfQxzElementEnum(String code, String name, String unit){
+        this.code = code;
+        this.name = name;
+        this.unit = unit;
+    }
+
+    public String getCode(){
+        return this.code;
+    }
+    public String getName(){
+        return this.name;
+    }
+
+    public String getUnit(){
+        return this.unit;
+    }
+
+
+    /**
+     * 根据code查找
+     * @param code 枚举code
+     * @return 枚举对象
+     */
+    public static YfqxzEnumFactor findEnumByCode(String code) {
+        for (YfqxzEnumFactor statusEnum : YfqxzEnumFactor.values()) {
+            if (statusEnum.getCode().equals(code)) {
+                return statusEnum;
+            }
+        }
+        return null;
+    }
+}