ZhuDongming
2019-06-05 944fcfc56ba96cb12466604d33194fc76965faa8
增加获取污染溯源接口
1 files modified
184 ■■■■■ changed files
src/main/java/com/moral/controller/ScreenController.java 184 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java
@@ -163,8 +163,7 @@
    /**
     * Screen login. 大屏登录
     * 
     * @param request
     *            the request
     * @param request the request
     * @return the map
     */
    @GetMapping("login")
@@ -219,12 +218,10 @@
        return resultMap;
    }
    /**
     * Gets the equipment states. 获取该账号下所有设备的状态
     * 
     * @param request
     *            the request
     * @param request the request
     * @return the equipment states
     */
    @GetMapping("/equipment-state")
@@ -237,12 +234,12 @@
    /**
     * Gets the alarm levels. 获取报警配置
     * 
     * @param request
     *            the request
     * @param request the request
     * @return the alarm levels
     */
    @GetMapping("alarm-levels")
    public Object getAlarmLevels(HttpServletRequest request, Optional<Integer> orgId, Optional<Integer> mpId,Optional<String> mac) {
    public Object getAlarmLevels(HttpServletRequest request, Optional<Integer> orgId, Optional<Integer> mpId,
            Optional<String> mac) {
        List<Map<String,Object>> sensorAlarmList = null;
        try {
            AlarmConfig alarmConfig = null;
@@ -269,7 +266,8 @@
                     if(alarmSensorLevel.getIncrement()!=null){
                         boolean isAllZero = alarmSensorLevel.getIncrement().stream().allMatch(item ->  item == 0);
                         if(isAllZero){
                             AlarmSensorLevel defaultAlarmSensorLevel = finalDefaultSensorLevelMap==null?null:finalDefaultSensorLevelMap.get(entry.getKey());
                            AlarmSensorLevel defaultAlarmSensorLevel = finalDefaultSensorLevelMap == null ? null
                                    : finalDefaultSensorLevelMap.get(entry.getKey());
                             if(defaultAlarmSensorLevel!=null){
                                 alarmSensorLevel.setIncrement(defaultAlarmSensorLevel.getIncrement());
                             }else{
@@ -302,8 +300,7 @@
    /**
     * Gets the standard by sensor.获取某传感器标准值
     *
     * @param macKey
     *            the request
     * @param macKey the request
     * @return the standard by sensor
     */
    @GetMapping("sensor-standard")
@@ -337,11 +334,11 @@
        // todo
        return  null;
    }
    /**
     * Gets the day AQI by sensor.设备昨日的AQI指标
     *
     * @param request
     *            the request
     * @param request the request
     * @return the day AQI by sensor
     */
    @GetMapping("day-aqi")
@@ -353,8 +350,7 @@
    /**
     * Gets the average by all. 获取某账号某区域10分钟前到5分钟前所有传感器平均数值排名
     * 
     * @param request
     *            the request
     * @param request the request
     * @return the average by all
     * @throws Exception 
     */
@@ -367,8 +363,7 @@
    /**
     * Gets the average by sensor.某个传感器一小时内所有设备排名
     *
     * @param request
     *            the request
     * @param request the request
     * @return the average by sensor
     */
    @GetMapping("sensor-average")
@@ -380,8 +375,7 @@
    /**
     * Gets the month average by sensor.设备传感器本月平均值
     *
     * @param request
     *            the request
     * @param request the request
     * @return the month average by sensor
     */
    @GetMapping("month-sensor-average")
@@ -473,18 +467,19 @@
    }
    /**
     * 地图接口
     * 开始
     * 地图接口 开始
     */
    /**
     * 地图主页
     *
     * @param model
     * @param code
     * @param accountId
     * @return
     */
    @RequestMapping(value = "/map-page", method = RequestMethod.GET)
    public ModelAndView map(ModelAndView model, @RequestParam("areaCode")long code, @RequestParam("accountId")int accountId){
    public ModelAndView map(ModelAndView model, @RequestParam("areaCode") long code,
            @RequestParam("accountId") int accountId) {
        Account account = accountService.getAccountById(accountId);
        String regionName = areaService.queryFullNameByCode(code);
        if(account!=null&&regionName!=null){
@@ -510,9 +505,11 @@
            return model;
        }
    }
    @RequestMapping(value="/get-monitorpoints",method = RequestMethod.GET)
    @ResponseBody
    public ResultBean getMonitorpointList(@RequestParam("orgId")String orgId,MapBounds mapBounds,@RequestParam("regionCode")String regionCode){
    public ResultBean getMonitorpointList(@RequestParam("orgId") String orgId, MapBounds mapBounds,
            @RequestParam("regionCode") String regionCode) {
        ResultBean<List<MonitorPoint>> resultBean = new ResultBean();
        Map<String,Object> paramMap = new HashMap<String, Object>();
        paramMap.put("orgId", orgId);
@@ -524,9 +521,11 @@
        resultBean.setCode(ResultBean.SUCCESS);
        return resultBean;
    }
    @RequestMapping(value="/get-devices",method = RequestMethod.GET)
    @ResponseBody
    public ResultBean getDevices(@RequestParam("orgId")Integer orgId,MapBounds mapBounds,@RequestParam("regionCode")String regionCode){
    public ResultBean getDevices(@RequestParam("orgId") Integer orgId, MapBounds mapBounds,
            @RequestParam("regionCode") String regionCode) {
        ResultBean<List<Device>> resultBean = new ResultBean();
        Map<String,Object> paramMap = new HashMap<String, Object>();
        paramMap.put("orgId", orgId);
@@ -538,26 +537,21 @@
        resultBean.setCode(ResultBean.SUCCESS);
        return resultBean;
    }
    @RequestMapping(value = "get-devices-for-popup",method = RequestMethod.GET)
    @ResponseBody
    public PageResult getDevicesForPopup(
            @RequestParam("orgId")Integer orgId,
            String name,
            Integer pageSize,
            Integer pageNo
    ){
    public PageResult getDevicesForPopup(@RequestParam("orgId") Integer orgId, String name, Integer pageSize,
            Integer pageNo) {
        return  deviceService.query(orgId,name,pageSize,pageNo);
    }
    @RequestMapping(value = "get-devices-by-mid-oid",method = RequestMethod.GET)
    @ResponseBody
    public PageResult getDevicesByMidOid(
            @RequestParam("orgId")Integer orgId,
            @RequestParam("mpId")Integer mpId,
            Integer pageSize,
            Integer pageNo
    ){
    public PageResult getDevicesByMidOid(@RequestParam("orgId") Integer orgId, @RequestParam("mpId") Integer mpId,
            Integer pageSize, Integer pageNo) {
       return deviceService.query(orgId,mpId,pageSize,pageNo);
    }
    @RequestMapping(value="/get-real-state-data",method = RequestMethod.POST)
    @ResponseBody
    public JsonData getRealStateAndData(@RequestBody JSONObject paramMap){
@@ -600,7 +594,8 @@
    }
    @GetMapping("report_avg_datas")
    public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request) throws Exception {
    public ResultBean<List<Map<String, Object>>> getMonitorPointOrDeviceAvgData(HttpServletRequest request)
            throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        ParameterUtils.getTimeType4Time(parameters);
        parameters.put("monitorPointId", parameters.remove("monitorPoint"));
@@ -644,6 +639,7 @@
    /**
     * 根据监控点id获取所属设备version数据集
     *
     * @param mptid
     * @return
     */
@@ -659,29 +655,27 @@
            @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"),
    })
            @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);
        List<Map<String, Object>> list = historyService.getRegionRankingData(parameters);
        return new ResultBean<List<Map<String, Object>>>(list);
    }
    // todo
    @Value(value = "classpath:system/realTimeMonitorLayout.json")
    private org.springframework.core.io.Resource resource;
    @ApiOperation(value = "获取实时监控页面布局", notes = "")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "primaryKey",defaultValue = "898607b0101730391967", value = "值为:设备mac或监控站id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", defaultValue = "device",value = "值为:'monitorPoint'或'device'", required = true, paramType = "query", dataType = "String"),
    })
            @ApiImplicitParam(name = "type", defaultValue = "device", value = "值为:'monitorPoint'或'device'", required = true, paramType = "query", dataType = "String"), })
    @GetMapping("rtm-layout")
    public ResultBean realTimeMonitorLayout(String primaryKey,String type){
        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
            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());
@@ -717,9 +711,9 @@
            @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 {
            @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);
        ParameterUtils.getTimeType4Time(parameters);
        parameters.put("monitorPointId", parameters.remove("monitorPoint"));
@@ -740,30 +734,31 @@
        }
        return new ResultBean<List<Map<String, Object>>>(list);
    }
    @GetMapping("getmpoint-byid")
    @ApiOperation(value = "获取监测站数据", notes = "获取监测站数据,包含名称、地址、坐标等详细信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "monitorPointId",defaultValue = "1",value = "监控站id", required = true, paramType = "query", dataType = "Integer"),
    })
            @ApiImplicitParam(name = "monitorPointId", defaultValue = "1", value = "监控站id", required = true, paramType = "query", dataType = "Integer"), })
    public ResultBean<MonitorPoint> getMonitorPointById(Integer monitorPointId){
        MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId);
        return new ResultBean<>(monitorPoint);
    }
    @Resource
    HangzhouAqiService hangzhouAqiService;
    @GetMapping("aqi24hours")
    @ApiOperation(value = "最近24小时aqi数值", notes = "最近24小时国控aqi数值")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "orgid",defaultValue = "5",value = "组织id", required = true, paramType = "query", dataType = "Integer"),
    })
            @ApiImplicitParam(name = "orgid", defaultValue = "5", value = "组织id", required = true, paramType = "query", dataType = "Integer"), })
    public ResultBean<List<Map<String,Object>>> getAqi24HoursNC(@RequestParam("orgid") Integer organizationId) {
        return new ResultBean<>(hangzhouAqiService.queryAqi24Hours(organizationId));
    }
    @GetMapping("mpt-dev-summary")
    @ApiOperation(value = "监控总数和设备状态信息", notes = "监控总数和设备状态信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "orgid",defaultValue = "5",value = "组织id", required = true, paramType = "query", dataType = "Integer"),
    })
            @ApiImplicitParam(name = "orgid", defaultValue = "5", value = "组织id", required = true, paramType = "query", dataType = "Integer"), })
    public ResultBean<Map> getMptAndDevSummary(@RequestParam("orgid") Integer organizationId){
          Map<String,Map> result = new HashMap<>(2);
          Integer mptCount = monitorPointService.countOfSubOrgs(organizationId);
@@ -778,8 +773,7 @@
    @GetMapping("weather")
    @ApiOperation(value = "获取区域天气情况", notes = "获取区域天气情况")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "organizationId",defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "String")
    })
            @ApiImplicitParam(name = "organizationId", defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "String") })
    public ResultBean<Map<String, Object>> getWeatherDataByRegion(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        Map<String, Object> map = weatherService.getWeatherDataByRegion(parameters);
@@ -792,8 +786,7 @@
            @ApiImplicitParam(name = "accountId",defaultValue = "1", value = "登录账号的id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorKey",defaultValue = "e1,e2,e3", value = "传感器key,如有多个用逗号分隔", required = true, paramType = "query", dataType = "String"), 
            @ApiImplicitParam(name = "time",defaultValue = "", value = "时间(long类型时间)", required = false, paramType = "query", dataType = "String"), 
            @ApiImplicitParam(name = "interval",defaultValue = "30", value = "时间间隔(秒)", required = true, paramType = "query", dataType = "Integer"),
    })
            @ApiImplicitParam(name = "interval", defaultValue = "30", value = "时间间隔(秒)", required = true, paramType = "query", dataType = "Integer"), })
    public ResultBean<Map<String, Object>> getActualDataByRegion(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        Map<String, Object> map = historyService.getActualDataByRegion(parameters);
@@ -803,8 +796,7 @@
    @GetMapping("quality")
    @ApiOperation(value = "获取优良天数", notes = "获取优良天数")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "organizationId",defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "String")
    })
            @ApiImplicitParam(name = "organizationId", defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "String") })
    public ResultBean<Map<String, Object>> getQualityCountDayByRegion(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        Map<String, Object> map = qualityDailyService.getQualityCountDayByRegion(parameters);
@@ -815,21 +807,19 @@
    @ApiOperation(value = "获取监控点以及设备", notes = "获取监控点以及设备")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "organizationId",defaultValue = "8", value = "登录账号的组织id", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "regionCode",defaultValue = "320583", value = "区域码", required = true, paramType = "query", dataType = "String")
    })
    public ResultBean<List<MonitorPoint>> getMonitorPointsAndDevicesByRegion(HttpServletRequest request) throws Exception {
            @ApiImplicitParam(name = "regionCode", defaultValue = "320583", value = "区域码", required = true, paramType = "query", dataType = "String") })
    public ResultBean<List<MonitorPoint>> getMonitorPointsAndDevicesByRegion(HttpServletRequest request)
            throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        List<MonitorPoint> monitorPoints= monitorPointService.getMonitorPointsAndDevicesByRegion(parameters);
        return new ResultBean<List<MonitorPoint>>(monitorPoints);
    }
    @GetMapping("devices-state")
    @ApiOperation(value = "刷新设备状态", notes = "刷新设备状态")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "organizationId",defaultValue = "8", value = "登录账号的组织id", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "regionCode",defaultValue = "320583", value = "区域码", required = true, paramType = "query", dataType = "String")
    })
            @ApiImplicitParam(name = "regionCode", defaultValue = "320583", value = "区域码", required = true, paramType = "query", dataType = "String") })
    public ResultBean<Collection<Object>> getDevicesStateByRegion(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Collection<Object> monitorPoints= monitorPointService.getDevicesStateByRegion(parameters);
@@ -845,14 +835,12 @@
            @ApiImplicitParam(name = "organizationId",defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "time",defaultValue = "2019", value = "查询的时间", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorKey",defaultValue = "e27", value = "查询的监测因子的key", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "regionCode",defaultValue = "130000", value = "区域码", required = true, paramType = "query", dataType = "String")
    })
            @ApiImplicitParam(name = "regionCode", defaultValue = "130000", value = "区域码", required = true, paramType = "query", dataType = "String") })
    public ResultBean<List<Map<String, Object>>> getemissionsData(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        List<Map<String, Object>> result = historyDailyService.getEmissionsData(parameters);
        return new ResultBean<List<Map<String, Object>>>(result);
    }
    @GetMapping("overproof")
    @ApiOperation(value = "浓度超标", notes = "浓度超标")
@@ -861,8 +849,7 @@
            @ApiImplicitParam(name = "time",defaultValue = "2019", value = "查询的时间", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorKey",defaultValue = "e27", value = "查询的监测因子的key", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "overproofRatio",defaultValue = "0", value = "超标比例(0,1,2,3)(超标,超标100%,超标200%,超标300%)", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "regionCode",defaultValue = "130000", value = "区域码", required = true, paramType = "query", dataType = "String")
    })
            @ApiImplicitParam(name = "regionCode", defaultValue = "130000", value = "区域码", required = true, paramType = "query", dataType = "String") })
    public ResultBean<Map> getOverproofData(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Map result = historyDailyService.getOverproofData(parameters);
@@ -872,8 +859,7 @@
    @GetMapping("limit-device")
    @ApiOperation(value = "获取设备的警报限值", notes = "获取设备的警报限值")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mac",defaultValue = "p5dnd7a0391956", value = "设备mac码", required = true, paramType = "query", dataType = "String")
    })
            @ApiImplicitParam(name = "mac", defaultValue = "p5dnd7a0391956", value = "设备mac码", required = true, paramType = "query", dataType = "String") })
    public ResultBean<List<Map<String, Object>>> getLimitDataByDevice(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        String density = deviceService.getLimitDataByDevice(parameters);
@@ -890,4 +876,58 @@
        return new ResultBean<List<Map<String, Object>>>(resuList);
    }
    /**
     * @description 根据设备mac,监测因子,时间查询返回界面
     * @author ZhuDongming
     * @date 2019-06-05 10:02:10
     * @param model
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping("/map-traceability")
    @ApiOperation(value = "获取污染溯源", notes = "获取污染溯源")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "monitorPointId", value = "监测点id", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "mac", value = "设备mac地址", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorKey", value = "查询的监测因子的key", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "查询时间", required = true, paramType = "query", dataType = "String") })
    public ModelAndView traceability(ModelAndView model, HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Integer monitorPointId = Integer.parseInt(parameters.get("monitorPointId").toString());
        MonitorPoint monitorPoint = monitorPointService.queryWithRelationById(monitorPointId);
        String mac = parameters.get("mac").toString();
        String sensorKey = parameters.get("sensorKey").toString();
        String time = parameters.get("time").toString();
        Long code = monitorPoint.getAreaCode().longValue();
        String regionName = areaService.queryFullNameByCode(code);
        Device device = deviceService.getDeviceByMac(mac, false);
        if (monitorPoint != null && mac != null && sensorKey != null && time != null) {
            Map<String, Double> resultMap = historyDailyService.getTraceabilityData(parameters);
            JSONObject params = new JSONObject();
            params.put("sensorInfo", resultMap);
            params.put("regionCode", code);
            params.put("regionName", regionName);
            params.put("monitorPoint", monitorPoint);
            params.put("device", device);
            String paramsJson = params.toJSONString();
            model.addObject("traceabilityParams", paramsJson);
            model.setViewName("traceability");
            return model;
        } else {
            StringBuilder msg = new StringBuilder();
            msg.append(" param[0] monitorPointId:");
            msg.append(monitorPointId.toString());
            msg.append(" param[0] mac:");
            msg.append(mac);
            msg.append(" param[0] sensorKey:");
            msg.append(sensorKey);
            msg.append(" param[0] time:");
            msg.append(time);
            log.warn(msg);
            model.setViewName("403");
            return model;
        }
    }
}