package com.ld.igds.three.service.impl; import com.alibaba.fastjson.JSONObject; import com.ld.igds.common.CoreThreeService; import com.ld.igds.es.dto.EsData; import com.ld.igds.es.service.CoreEsService; import com.ld.igds.models.ThreeConf; import com.ld.igds.three.ThreeCodeEnum; import com.ld.igds.three.ThreeConstant; import com.ld.igds.three.data.Data5001; import com.ld.igds.three.data.ThreeResponse; import com.ld.igds.three.param.ThreeCommonParam; import com.ld.igds.three.param.ThreeRequest; import com.ld.igds.three.service.ThreeService; import com.ld.igds.three.util.ThreeRespUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * 5001-能耗数据查看接口实现 * * @author chen */ @Service public class ThreeServiceImpl5001 implements ThreeService { @Autowired private CoreThreeService commonService; @Autowired private CoreEsService esService; @Override public String getInterfaceId() { return ThreeConstant.API_THREE_5001; } @SuppressWarnings("unchecked") @Override public ThreeResponse execute(ThreeRequest req) { //转化请求参数 ThreeCommonParam param = JSONObject.parseObject(req.getData().toString(), ThreeCommonParam.class); //判断uid if (StringUtils.isEmpty(param.getUid())) { return ThreeRespUtil.error(ThreeCodeEnum.CODE_1005, req); } //获取所有仓库的能耗信息 Map esMap = esService.getCacheEsDataMap(req.getCompanyId()); if(esMap == null){ return ThreeRespUtil.error(ThreeCodeEnum.CODE_1111, "没有获取到实时信息!", req); } List list = new ArrayList<>(); //根据uid判断查询所有设备信息还是查询某个仓库设备信息 if (ThreeConstant.REQUEST_UID.equals(param.getUid())) { //获取所有三维配置信息 List threeList = commonService.getCacheThreeAll(req.getCompanyId()); if(threeList == null || threeList.isEmpty()){ return ThreeRespUtil.error(ThreeCodeEnum.CODE_1111, "未查询相关三维配置信息,请联系管理员!", req); } //返回数据处理 for (ThreeConf threeConf : threeList) { if (StringUtils.isEmpty(threeConf.getDeviceId()) && StringUtils.isNotEmpty(threeConf.getDepotId())) { getData(threeConf, esMap, list); } } } else { //获取单个仓库的三维配置信息 ThreeConf threeConf = commonService.getCacheThreeConfById(req.getCompanyId(), param.getUid()); if(threeConf == null){ return ThreeRespUtil.error(ThreeCodeEnum.CODE_1111, "未查询到此uid的配置信息,请联系管理员!", req); } getData(threeConf, esMap, list); } return ThreeRespUtil.success(list, req); } /** * 数据封装 * * @param threeConf * @param esMap * @param list * @return */ private void getData(ThreeConf threeConf, Map esMap, List list) { EsData esData = esMap.get(threeConf.getDepotId()); Data5001 data = new Data5001(); data.setUid(threeConf.getUid()); data.setTime(esData.getUpdateTime()); data.setUa(esData.getUa()); data.setUb(esData.getUb()); data.setUc(esData.getUc()); data.setIa(esData.getIa()); data.setIb(esData.getIb()); data.setIc(esData.getIc()); data.setEs(esData.getEs()); data.setEsInc(esData.getEsInc()); list.add(data); } }