package com.fastbee.data.service.devicedetail.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.core.domain.CommonResult;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.model.vo.iot.DeviceDetailVo;
import com.fastbee.common.model.vo.iot.QueryLogVo;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.DevParamsUtils;
import com.fastbee.common.utils.NumberUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.data.domain.vo.AnfangInfoVo;
import com.fastbee.data.service.devicedetail.IDeviceDetailService;
import com.fastbee.data.controller.anfang.service.IUploadedPhotosService;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.domain.ThingsModel;
import com.fastbee.iot.haiwei.service.HaiWeiService;
import com.fastbee.iot.mapper.DeviceMapper;
import com.fastbee.iot.model.anfang.UploadedPhotos;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo;
import com.fastbee.iot.model.haiwei.HaiWeiDeviceInfoVo;
import com.fastbee.iot.model.haiwei.HaiWeiPropertyVo;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto;
import com.fastbee.iot.service.IDeviceLogService;
import com.fastbee.iot.service.IDeviceService;
import com.fastbee.iot.service.IThingsModelService;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.domain.dto.MaGuangaiRecordDto;
import com.fastbee.waterele.domain.dto.MaWatereleRecordDto;
import com.fastbee.waterele.service.IMaWatereleRecordService;
import com.fastbee.xunjian.domain.XjInspectionRecords;
import com.fastbee.xunjian.domain.XjInspectionRoutes;
import com.fastbee.xunjian.mapper.XjInspectionRecordsMapper;
import com.fastbee.xunjian.mapper.XjInspectionRoutesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class DeviceDetailServiceImpl implements IDeviceDetailService {

    private final DeviceMapper deviceMapper;

    @Autowired
    public IDeviceService iDeviceService;
    @Autowired
    private IThingsModelService thingsModelService;
    @Autowired
    private XjInspectionRoutesMapper xjInspectionRoutesMapper;
    @Autowired
    private XjInspectionRecordsMapper xjInspectionRecordsMapper;
    @Autowired
    private HaiWeiService haiWeiService;

    @Autowired
    private IUploadedPhotosService uploadedPhotosService;

    @Autowired
    private IDeviceLogService logService;
    @Resource
    private IMaWatereleRecordService watereleRecordService;

    public DeviceDetailServiceImpl(DeviceMapper deviceMapper) {
        this.deviceMapper = deviceMapper;
    }

    @Override
    public List<MaWatereleRecord> shuakaRecord(MaWatereleRecordDto maWatereleRecordDto) {
        //todo
        return Collections.emptyList();
    }

    @Override
    public List<MaGuangaiRecordDto> guangaiRecord(MaGuangaiRecordDto maWatereleRecordDto) {
        //todo
        return Collections.emptyList();
    }

    @Override
    public List<Device> getBindDevices(String ids) {
        String[] idArray = ids.split(",");
        List<Long> idList = new ArrayList<>();
        for (String id : idArray) {
            try {
                idList.add(Long.parseLong(id));
            } catch (Exception e) {
            }
        }
        List<Device> devices = deviceMapper.selectDeviceListByDeviceIds(idList);
        return devices;
    }

    @Override
    public ArrayList<Object> gongdianChart(QueryLogVo queryLogVo) {
        Long deviceId = queryLogVo.getDeviceId();
        if (deviceId == null) {
            throw new RuntimeException("请上传devicerId");
        }
        Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
        if (device == null) {
            throw new RuntimeException("未查到该设备");
        }
        Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
        //太阳能设备
        String taiyangnengIds = devParams.get("taiyangnIds").toString();
        if (taiyangnengIds == null) {
            return new ArrayList<>();
        }
        ArrayList<Object> deviceLogAllCurves =
                iDeviceService.getDeviceLogAllCurves(Long.parseLong(taiyangnengIds), queryLogVo.getStartTime(), queryLogVo.getEndTime());
        return deviceLogAllCurves;
    }

    @Override
    public List<Object> yongshuiChart(QueryLogVo queryLogVo) {
        Long deviceId = queryLogVo.getDeviceId();
        if (deviceId == null) {
            throw new RuntimeException("请上传devicerId");
        }
        Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
        if (device == null) {
            throw new RuntimeException("未查到该设备");
        }
        Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
        //太阳能设备
        String liuliangIds = devParams.get("liuliangIds").toString();
        if (liuliangIds == null) {
            return new ArrayList<>();
        }
        ArrayList<Object> deviceLogAllCurves =
                iDeviceService.getDeviceLogAllCurves(Long.parseLong(liuliangIds), queryLogVo.getStartTime(), queryLogVo.getEndTime());
        return deviceLogAllCurves;
    }


    @Override
    public List<XjInspectionRecords> xunjianRecord(QueryLogVo queryLogVo) {
        //todo
        Long deviceId = queryLogVo.getDeviceId();
        if (deviceId == null) {
            throw new RuntimeException("请上传devicerId");
        }
        Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
        if (device == null) {
            throw new RuntimeException("未查到该设备");
        }
        XjInspectionRoutes xjInspectionRoutes = new XjInspectionRoutes();
        xjInspectionRoutes.setEngineeringObjectId(deviceId);
        xjInspectionRoutes.setEngineeringObjectType("1");
        List<XjInspectionRoutes> xjInspectionRoutes1 = xjInspectionRoutesMapper.selectXjInspectionRoutesList(xjInspectionRoutes);
        if (xjInspectionRoutes1.size() > 0) {
            List<XjInspectionRecords> xjInspectionRecordsList = new ArrayList<>();
            XjInspectionRecords xjInspectionRecords = new XjInspectionRecords();
            xjInspectionRecords.setInspectionRouteId(xjInspectionRoutes1.get(0).getId());
            xjInspectionRecords.setChaxunBeginTime(queryLogVo.getStartTime());
            xjInspectionRecords.setChaxunEndTime(queryLogVo.getEndTime());
            xjInspectionRecordsList = xjInspectionRecordsMapper.selectXjInspectionRecordsList(xjInspectionRecords);
            return xjInspectionRecordsList;
        }
        return new ArrayList<>();
    }

    @Override
    public AnfangInfoVo anfangInfo(Long deviceId) {
        //获取监控设备信息
        Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
        if (device == null) {
            throw new RuntimeException("未查到该设备");
        }
        AnfangInfoVo anfangInfoVo = new AnfangInfoVo();
        //获取设备参数
        Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
        //安防设备
        String jiankongIds = devParams.get("jiankongIds").toString();
        if (StringUtils.isNotEmpty(jiankongIds)) {
            Device jiankongDevice = iDeviceService.selectDeviceByDeviceId(Long.parseLong(jiankongIds));
            anfangInfoVo.setJiankongDevice(jiankongDevice);
        }
        //安防设备
        String anfangIds = devParams.get("anfangIds").toString();
        //获取设备安防状态
        if (StringUtils.isNotEmpty(anfangIds)) {
            Device anfangDevice = iDeviceService.selectDeviceByDeviceId(Long.parseLong(anfangIds));
            //获取当前安防告警状态
            anfangInfoVo.setDoorStatus(0);
            CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(anfangDevice.getDeviceId());
            if(cache != null){
                HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
                if(checkedData != null){
                    List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
                    for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
                        if (haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_open")) {
                            anfangInfoVo.setDoorStatus(Integer.parseInt(haiWeiPropertyVo.getValue().toString()));
                        }
                    }
                }
            }
            UploadedPhotos uploadedPhotos = new UploadedPhotos();
            uploadedPhotos.setSn(anfangDevice.getSerialNumber());
            List<UploadedPhotos> uploadedPhotos1 = uploadedPhotosService.selectUploadedPhotosList(uploadedPhotos);
            int doorStatus = 0;//0=正常，1=箱门振动，2=箱门打开
            if (uploadedPhotos1.size() > 0) {
                UploadedPhotos temp = uploadedPhotos1.get(0);
//                if (new Date().getTime() - temp.getUploadTime().getTime() < 36000000) {
//                    if (temp.getShakeState().equals("1")) {
//                        doorStatus = 1;
//                    }
//                    if (temp.getDoorState().equals("1")) {
//                        doorStatus = 2;
//                    }
//                }
            }
            if (uploadedPhotos1.size() > 5) {
                uploadedPhotos1 = uploadedPhotos1.subList(0, 5);
            }
//            anfangInfoVo.setDoorStatus(doorStatus);
            anfangInfoVo.setAnfangList(uploadedPhotos1);
        }
        //安防设备
        String guimenIds = devParams.get("guimenIds").toString();
        if (StringUtils.isNotEmpty(guimenIds)) {
            anfangInfoVo.setGuimenId(devParams.get("guimenIds").toString());
        }
        return anfangInfoVo;
    }

    @Override
    public List<HashMap<Object, Object>> gongdianRealData(QueryLogVo queryLogVo) {
        Long deviceId = queryLogVo.getDeviceId();
        if (deviceId == null) {
            throw new RuntimeException("请上传devicerId");
        }
        Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
        if (device == null) {
            throw new RuntimeException("未查到该设备");
        }
        DateTime dateTime = DateUtil.date(new Date());
        Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
        //太阳能设备
        String taiyangnengIds = devParams.get("taiyangnIds").toString();
        ThingsModel thingsModel1 = new ThingsModel();
        thingsModel1.setProductId(138L);
        List<ThingsModel> taiyangnengModels = thingsModelService.selectThingsModelList(thingsModel1);
        taiyangnengModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
        List<HashMap<Object, Object>> list = new ArrayList<>();
        CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(Long.parseLong(taiyangnengIds));
        if(cache != null){
            HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
            if(checkedData != null){
                List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
                for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
                    if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_kaixian")){
                        continue;
                    }
                    HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
                        put("upType", 0);
                        put("identifier", haiWeiPropertyVo.getNameEn());
                        put("unit", haiWeiPropertyVo.getUnit());
                        put("value", haiWeiPropertyVo.getValue());
                        put("name", haiWeiPropertyVo.getNameCn());
                    }};
                    if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_MpptDown")){

                        hashMap.put("value", NumberUtils.isNumeric(haiWeiPropertyVo.getValue().toString())?(
                                Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?"正常":"异常"):"正常");
                    }
                    if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_市电状态")){
                        hashMap.put("value", NumberUtils.isNumeric(haiWeiPropertyVo.getValue().toString())?(
                                Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?"市电":"太阳能"):"市电");
                    }
                    list.add(hashMap);
                }
            }
        }
//        if (StringUtils.isNotEmpty(taiyangnengIds)) {
//            Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(taiyangnengIds));
//            List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
//                setSerialNumber(taiyangnengDevice.getSerialNumber());
//                setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
//                setEndTime(DateUtil.endOfDay(dateTime).toString());
//            }});
//            Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
//                    .comparing(DeviceLog::getCreateTime, Comparator
//                            .nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
//            for (ThingsModel thingsModel : taiyangnengModels) {
//                HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
//                    put("upType", 0);
//                    put("identifier", thingsModel.getIdentifier());
//                    put("unit", "");
//                    put("value", 0);
//                    put("name", thingsModel.getModelName());
//                }};
//                if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
//                    String specs = thingsModel.getSpecs();
//                    JSONObject parse = (JSONObject) JSON.parse(specs);
//                    if (parse.containsKey("unit")) {
//                        hashMap.put("unit", parse.get("unit"));
//                    }
//                }
//
//                if (hashMap.size() > 1) {
//                    List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
//                    if (deviceLogs1 != null) {
//                        if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
//                            if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
//                                hashMap.put("upType", 1);
//                            } else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
//                                hashMap.put("upType", -1);
//                            }
//                            hashMap.put("value", deviceLogs1.get(0).getLogValue());
//                        } else {
//                            hashMap.put("value", "--");
//                            hashMap.put("upType", 0);
//                        }
//
//                    }
//                } else if (hashMap.size() > 0) {
//                    List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
//                    if (deviceLogs2 != null) {
//                        hashMap.put("value", deviceLogs2.get(0).getLogValue());
//                    }
//                }
//                list.add(hashMap);
//            }
//        } else {
//            for (ThingsModel thingsModel : taiyangnengModels) {
//                HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
//                    put("upType", 0);
//                    put("identifier", thingsModel.getIdentifier());
//                    put("unit", "");
//                    put("value", 0);
//                    put("name", thingsModel.getModelName());
//                }};
//                list.add(hashMap);
//            }
//        }
        return list;
    }

    @Override
    public List<HashMap<Object, Object>> yongshuiRealData(QueryLogVo queryLogVo) {
        Long deviceId = queryLogVo.getDeviceId();
        if (deviceId == null) {
            throw new RuntimeException("请上传devicerId");
        }
        Device device = iDeviceService.selectDeviceByDeviceId(deviceId);
        if (device == null) {
            throw new RuntimeException("未查到该设备");
        }
        DateTime dateTime = DateUtil.date(new Date());
        Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
        //太阳能设备
        String liuliangIds = devParams.get("liuliangIds").toString();
        ThingsModel thingsModel1 = new ThingsModel();
        thingsModel1.setProductId(139L);
        List<ThingsModel> liuliangModels = thingsModelService.selectThingsModelList(thingsModel1);
        liuliangModels.sort(Comparator.comparing(ThingsModel::getModelOrder));
        List<HashMap<Object, Object>> list = new ArrayList<>();
        CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(Long.parseLong(liuliangIds));
        if(cache != null){
            HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
            if(checkedData != null){
                List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
                for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
                    if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_kaixian")){
                        continue;
                    }
                    HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
                        put("upType", 0);
                        put("identifier", haiWeiPropertyVo.getNameEn());
                        put("unit", haiWeiPropertyVo.getUnit());
                        put("value", haiWeiPropertyVo.getValue());
                        put("name", haiWeiPropertyVo.getNameCn());
                    }};
                    if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_guanxian")){
                        hashMap.put("value",  NumberUtils.isNumeric(haiWeiPropertyVo.getValue().toString())?(
                                Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?"关闭":"开启"):"关闭");
                    }
                    if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_FlowDown")){
                        hashMap.put("value",  NumberUtils.isNumeric(haiWeiPropertyVo.getValue().toString())?(
                                Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?"正常":"异常"):"正常");
                    }
                    if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_mCon")){
                        hashMap.put("value", NumberUtils.isNumeric(haiWeiPropertyVo.getValue().toString())?(
                                Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 1f?"正常":"异常"):"正常");
                    }
                    list.add(hashMap);
                }
            }
        }
//        if (StringUtils.isNotEmpty(liuliangIds)) {
//            Device taiyangnengDevice = deviceMapper.selectDeviceByDeviceId(Long.parseLong(liuliangIds));
//            List<DeviceLog> deviceLogs = logService.selectDeviceLogList(new DeviceLog() {{
//                setSerialNumber(taiyangnengDevice.getSerialNumber());
//                setBeginTime(DateUtil.beginOfDay(DateUtil.offsetDay(dateTime, -1)).toString());
//                setEndTime(DateUtil.endOfDay(dateTime).toString());
//            }});
//            Map<String, List<DeviceLog>> taiyangnengCollect = deviceLogs.stream().sorted(Comparator
//                    .comparing(DeviceLog::getCreateTime, Comparator
//                            .nullsFirst(Comparator.naturalOrder())).reversed()).collect(Collectors.groupingBy(t -> t.getIdentity()));
//            for (ThingsModel thingsModel : liuliangModels) {
//                HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
//                    put("upType", 0);
//                    put("identifier", thingsModel.getIdentifier());
//                    put("unit", "");
//                    put("value", 0);
//                    put("name", thingsModel.getModelName());
//                }};
//                if (StringUtils.isNotEmpty(thingsModel.getSpecs())) {
//                    String specs = thingsModel.getSpecs();
//                    JSONObject parse = (JSONObject) JSON.parse(specs);
//                    if (parse.containsKey("unit")) {
//                        hashMap.put("unit", parse.get("unit"));
//                    }
//                }
//
//                if (hashMap.size() > 1) {
//                    List<DeviceLog> deviceLogs1 = taiyangnengCollect.get(thingsModel.getIdentifier());
//                    if (deviceLogs1 != null) {
//                        if (StringUtils.isNotEmpty(deviceLogs1.get(0).getLogValue())) {
//                            if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) == Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
//                                hashMap.put("upType", 1);
//                            } else if (Float.parseFloat(deviceLogs1.get(0).getLogValue()) < Float.parseFloat(deviceLogs1.get(1).getLogValue())) {
//                                hashMap.put("upType", -1);
//                            }
//                            hashMap.put("value", deviceLogs1.get(0).getLogValue());
//                        } else {
//                            hashMap.put("value", "--");
//                            hashMap.put("upType", 0);
//                        }
//
//                    }
//                } else if (hashMap.size() > 0) {
//                    List<DeviceLog> deviceLogs2 = taiyangnengCollect.get(thingsModel.getIdentifier());
//                    if (deviceLogs2 != null) {
//                        hashMap.put("value", deviceLogs2.get(0).getLogValue());
//                    }
//                }
//                list.add(hashMap);
//            }
//        } else {
//            for (ThingsModel thingsModel : liuliangModels) {
//                HashMap<Object, Object> hashMap = new HashMap<Object, Object>() {{
//                    put("upType", 0);
//                    put("identifier", thingsModel.getIdentifier());
//                    put("unit", "");
//                    put("value", 0);
//                    put("name", thingsModel.getModelName());
//                }};
//                list.add(hashMap);
//            }
//        }
        return list;
    }

    @Override
    public CommonResult<CmdHaiWeiVo> cmdDevices(CmdHaiWeiDto cmdHaiWeiDto) {
        String url = "https://cloud.haiwell.com/api/project/machine/datagroup/setTagsValue";
        Device deviceEntity = deviceMapper.selectDeviceByDeviceId(cmdHaiWeiDto.getDeviceId());
        Map<String, Object> devParams1 = DevParamsUtils.getDevParams(deviceEntity.getDevParams());
        String guimenIds = devParams1.get("guimenIds").toString();
        if (StringUtils.isEmpty(guimenIds)) {
            return null;
        }
        cmdHaiWeiDto.setDeviceId(Long.valueOf(guimenIds));
        return haiWeiService.cmdDevices(cmdHaiWeiDto);
    }

    /**
     * 获取设备详细信息
     * @param device
     */
    @Override
    public DeviceDetailVo getDetailInfo(Device device) {
        DeviceDetailVo deviceDetailVo = new DeviceDetailVo();
        //运行状态，最后一次更新时间
        MaWatereleRecord watereleRecord = new MaWatereleRecord();
        watereleRecord.setDevSn(device.getSerialNumber());
        TableDataInfo tableDataInfo = watereleRecordService.selectMaWatereleRecordList(watereleRecord);
        List<MaWatereleRecord> rows = (List<MaWatereleRecord>) tableDataInfo.getRows();
        //运行状态
        deviceDetailVo.setRunState("未运行");
        //累计用电量
        deviceDetailVo.setSumEle("--kwh");
        //最近一次上传时间
        deviceDetailVo.setLastDataTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,
                new Date()));
        if(rows.size()> 0){
            MaWatereleRecord item = rows.get(0);
            deviceDetailVo.setLastDataTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,
                    item.getCreateTime()));
            if(item.getWorkstate() == 0){
                deviceDetailVo.setRunState("未运行");
            }else {
                deviceDetailVo.setRunState("运行中");
            }
            deviceDetailVo.setSumEle(item.getSumele()+"kwh");
        }
        Map<String, Object> devParams = DevParamsUtils.getDevParams(device.getDevParams());
        //累计水量
        deviceDetailVo.setSumFlow("--m³");
        if(devParams.containsKey("liuliangIds")){
            String liuliangIds = devParams.get("liuliangIds").toString();
            //获取
            CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(Long.valueOf(liuliangIds));
            HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
            List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
            for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
                if (haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_sumFlow")) {
                    deviceDetailVo.setSumFlow(haiWeiPropertyVo.getValue()+"m³");
                }
            }
        }
        //供电信息
        //环境温度
        deviceDetailVo.setTemp("--℃");
        //供电方式
        deviceDetailVo.setGongDianType("市电");
        //电池电量
        deviceDetailVo.setPowerDianliang("--%");
        //电池电压
        deviceDetailVo.setPowerVolt("--V");
        //电池电流
        deviceDetailVo.setPowerCur("--A");
        if(devParams.containsKey("taiyangnIds")){
            String taiyangIds = devParams.get("taiyangnIds").toString();
            //获取
            CommonResult<HaiWeiDeviceInfoVo> cache = haiWeiService.getCache(Long.valueOf(taiyangIds));
            HaiWeiDeviceInfoVo checkedData = cache.getCheckedData();
            List<HaiWeiPropertyVo> propertyList = checkedData.getPropertyList();
            for (HaiWeiPropertyVo haiWeiPropertyVo : propertyList) {
                if (haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_市电状态")) {
                    try{
                        if(Float.parseFloat(haiWeiPropertyVo.getValue().toString()) == 0){
                            deviceDetailVo.setGongDianType("太阳能");
                        }
                    }catch (Exception e){
                    }

                }else if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_bat")){
                    deviceDetailVo.setPowerDianliang(haiWeiPropertyVo.getValueAndUnit());
                }else if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_batVolt")){
                    deviceDetailVo.setPowerVolt(haiWeiPropertyVo.getValueAndUnit());
                }else if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_batCur")){
                    deviceDetailVo.setPowerCur(haiWeiPropertyVo.getValueAndUnit());
                }else if(haiWeiPropertyVo.getNameEn().equals("三菱FX2N_1_airTemp")){
                    deviceDetailVo.setTemp(haiWeiPropertyVo.getValueAndUnit());
                }
            }
        }
        return deviceDetailVo;
    }


}
