From d6a0ac523af2db9216d30fabf1063c095c5b41e1 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Fri, 06 Jul 2018 15:52:39 +0800 Subject: [PATCH] app接口 --- src/main/java/com/moral/controller/ScreenController.java | 97 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 77 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java index 79beb59..064270e 100644 --- a/src/main/java/com/moral/controller/ScreenController.java +++ b/src/main/java/com/moral/controller/ScreenController.java @@ -15,6 +15,8 @@ import com.moral.entity.alarm.AlarmConfig; import com.moral.entity.alarm.AlarmConfigValue; import com.moral.entity.charts.DataSortCondition; +import com.moral.entity.layout.RealTimeDeviceLayout; +import com.moral.service.*; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.net.ftp.FTPClient; import org.apache.log4j.Logger; @@ -45,16 +47,6 @@ import com.moral.common.util.ValidateUtil; import com.moral.common.xml.Version; import com.moral.entity.alarm.AlarmSensorLevel; -import com.moral.service.AccountService; -import com.moral.service.AlarmConfigService; -import com.moral.service.AlarmDailyService; -import com.moral.service.AreaService; -import com.moral.service.DeviceService; -import com.moral.service.HistoryMinutelyService; -import com.moral.service.HistoryService; -import com.moral.service.MachineActivateService; -import com.moral.service.MonitorPointService; -import com.moral.service.SensorService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -68,7 +60,7 @@ @RequestMapping("/screen") //@CrossOrigin(origins = "*", maxAge = 3600) @SuppressWarnings({ "rawtypes", "unchecked", "unused" }) -@Api(tags = "Screen", description = "������������") +@Api(tags = "Screen", description = "������������") public class ScreenController { public static Logger log = Logger.getLogger(ScreenController.class); @Resource @@ -80,6 +72,8 @@ SensorService sensorService; @Resource MonitorPointService monitorPointService; + @Resource + DeviceVersionService deviceVersionService; /** The screen service. */ @Resource @@ -112,6 +106,10 @@ @Resource private AlarmDailyService alarmDailyService; + @Resource + private OrganizationLayoutService orgLayoutService; + @Resource + private DeviceVersionService dviceVersionService; /** * Screen login. ������������ * @@ -155,7 +153,7 @@ * @return the alarm levels */ @GetMapping("alarm-levels") - public Object getAlarmLevels(HttpServletRequest request, Optional<Integer> orgId, Optional<Integer> mpId) { + public Object getAlarmLevels(HttpServletRequest request, Optional<Integer> orgId, Optional<Integer> mpId,Optional<String> mac) { List<Map<String,Object>> sensorAlarmList = null; try { AlarmConfig alarmConfig = null; @@ -163,6 +161,8 @@ alarmConfig = alarmConfigService.queryValueByOrganizationId(orgId.get()).get(); }else if(mpId.isPresent()){ alarmConfig = alarmConfigService.queryByMonitorPointId(mpId.get()).get(); + } else if(mac.isPresent() ){ + alarmConfig = alarmConfigService.queryByDeviceMac(mac.get()).get(); } //��������������� if(alarmConfig.getValue()!=null&&alarmConfig.getValue().getAlarmLevels()!=null){ @@ -566,6 +566,7 @@ @ApiImplicitParam(name = "dimension", value = "������(profession���region���monitorPoint������)", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "sensorKey", value = "���������key", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "accountId", value = "������id", required = true, paramType = "query", dataType = "int"), + @ApiImplicitParam(name = "timeType", value = "������������(month���day���hour������)", required = true, paramType = "query", dataType = "int"), }) public ResultBean<List<Map<String, Object>>> getRegionRankingData(HttpServletRequest request){ Map<String, Object> parameters = getParametersStartingWith(request, null); @@ -582,15 +583,71 @@ }) @GetMapping("rtm-layout") public ResultBean realTimeMonitorLayout(String primaryKey,String type){ - InputStreamReader reader = null; - Map<String,Object> map = null; - try { - reader = new InputStreamReader(resource.getInputStream(),"UTF-8"); - map = new JSONReader(reader).readObject(new TypeReference<Map<String,Object>>() {}); - } catch (IOException e) { - e.printStackTrace(); + RealTimeDeviceLayout rtdLayout = null; + if(type != null && type.equals("device")) { + Device device = deviceService.getDeviceByMac(primaryKey,false); + if(device!= null + && device.getOrganizationIds()!=null + && device.getOrganizationIds().size() >0 + && device.getDeviceVersionId()!=null) { + Integer orgId = device.getOrganizationIds().get(0); + DeviceVersion deviceVersion = deviceVersionService.queryVersionById(device.getDeviceVersionId()); + rtdLayout = orgLayoutService.queryRtdLayoutWithUnit(orgId,deviceVersion.getVersion()); + }else { + return ResultBean.fail(); + } + + } else { + MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(Integer.parseInt(primaryKey)); + List<DeviceVersion> versionList = deviceVersionService.queryByMpointId(monitorPoint.getId()); + if(versionList.size() > 0) { + List<Integer> versionNolist = versionList.stream().map(item -> { + return item.getVersion(); + }).collect(Collectors.toList()); + rtdLayout = orgLayoutService.queryRtdLayoutWithUnit(monitorPoint.getOrganizationId(),versionNolist); + if(rtdLayout == null) { + return ResultBean.fail(); + } + } } - return new ResultBean(map); + if(rtdLayout!=null && rtdLayout.getDefaultMonitorItems().size() == 0 ) { + rtdLayout.getDefaultMonitorItems().addAll(rtdLayout.getCoreMonitorItems()); + } + return new ResultBean(rtdLayout == null? new RealTimeDeviceLayout():rtdLayout); + } + + @GetMapping("report_avg_data") + @ApiOperation(value = "������������������������������", notes = "������������������������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "monitorPoint", value = "���������id", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "mac", value = "������mac", required = false, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "sensorKey", value = "���������key,���������������������������", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "time", value = "������,������(���������2018-03)", required = true, paramType = "query", dataType = "String"), + }) + public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgDataBySensorKey(HttpServletRequest request) throws Exception { + Map<String, Object> parameters = getParametersStartingWith(request, null); + int length = ((String)parameters.get("time")).split("-").length; + if (length == 2) { + parameters.put("type", "month"); + } else if (length == 3){ + parameters.put("type", "day"); + } + parameters.put("monitorPointId", parameters.remove("monitorPoint")); + String[] sensorKeys = parameters.remove("sensorKey").toString().split(","); + parameters.put("sensors", Arrays.asList(sensorKeys)); + List<Map<String, Object>> list = historyMinutelyService.getMonitorPointOrDeviceAvgData(parameters); + + for (Map<String, Object> map : list) { + String time = map.get("time").toString(); + time = time.substring(time.length() - 2); + map.put("time", Integer.valueOf(time)); + List<Number> values = new ArrayList<Number>(); + for (String string : sensorKeys) { + values.add((Number) map.remove(string)); + } + map.put("values", values); + } + return new ResultBean<List<Map<String, Object>>>(list); } } -- Gitblit v1.8.0