jinpengyong
2021-07-21 7c50c777eda4fa9dfdf54535a7d6ab0520243267
screen-api/src/main/java/com/moral/api/controller/WebController.java
@@ -10,12 +10,16 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.moral.api.service.DeviceService;
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryFiveMinutelyService;
import com.moral.api.service.HistoryHourlyService;
import com.moral.api.service.SysAreaService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
@@ -31,6 +35,15 @@
    @Autowired
    private HistoryDailyService historyDailyService;
    @Autowired
    private HistoryFiveMinutelyService historyFiveMinutelyService;
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private SysAreaService sysAreaService;
    @GetMapping("getHourlyAqi")
    @ApiOperation(value = "获取一小时AQI", notes = "获取一小时AQI")
@@ -63,4 +76,69 @@
        return ResultMessage.ok(result);
    }
    @GetMapping("getWindData")
    @ApiOperation(value = "获取风场数据", notes = "获取风场数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "monitorPointId", value = "站点id", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getWindData(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("monitorPointIds")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        String[] monitorPointIds = params.remove("monitorPointIds").toString().split(",");
        params.put("monitorPointIds", monitorPointIds);
        List<Object> result = historyFiveMinutelyService.getAreaWindData(params);
        return ResultMessage.ok(result);
    }
    @GetMapping("getMacSensors")
    @ApiOperation(value = "根据mac获取对应所有因子", notes = "根据mac获取对应所有因子")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getMacSensors(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String, Object> sensorsInfo = deviceService.getSensorsByMac(params.get("mac").toString());
        return ResultMessage.ok(sensorsInfo);
    }
    @GetMapping("getTrendChartData")
    @ApiOperation(value = "获取监测因子趋势图数据", notes = "获取监测因子趋势图数据")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensorCode", value = "因子code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "数据类型,日(day),月(month),年(year)", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "数据时间", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getTrendChartData(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("sensorCode") || !params.containsKey("type") || !params.containsKey("time")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> sensorsInfo = deviceService.getTrendChartData(params);
        return ResultMessage.ok(sensorsInfo);
    }
    @GetMapping("getMapPath")
    @ApiOperation(value = "获取当前用户地图权限", notes = "获取当前用户地图权限")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "organizationId", value = "组织id", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage getMapPath(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("organizationId")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> result = sysAreaService.getMapPath(Integer.parseInt(params.get("organizationId").toString()));
        return ResultMessage.ok(result);
    }
}