package com.usky.controller.top; import com.alibaba.fastjson.JSONObject; import com.usky.annotion.AutoLog; import com.usky.constant.CommonConstant; import com.usky.entity.mqtt.TbDeviceInfoDTO; import com.usky.entity.mqtt.vo.TbDeviceAlarmsVO; import com.usky.entity.mqtt.vo.TbDeviceInfoVO; import com.usky.entity.mqtt.vo.TbDeviceVO; import com.usky.entity.mqtt.vo.TbDeviceVOTop; import com.usky.service.top.TopServcie; import com.usky.utils.HttpUtils; import com.usky.utils.Page; import com.usky.utils.RedisUtil; import com.usky.utils.Result; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author laowo * @version v1.0 * @date 2021/8/10 17:25 * @description TODO **/ @RestController @RequestMapping("jx/top") @Api(tags = "首页") public class TopController { @Autowired private TopServcie topServcie; @Autowired private RedisUtil redisUtil; @GetMapping("listDeviceStatus") @ApiOperation(value = "首页-设备状态统计") @ApiImplicitParams({ }) public Result listDeviceStatus() { Map result = topServcie.listDeviceStatus(); return Result.OK(result); } @GetMapping("listAlarmsSe") @ApiOperation(value = "首页-七日告警统计") @ApiImplicitParams({ }) public Result listAlarmsSe() { List result = topServcie.listAlarmsSe(); return Result.OK(result); } @GetMapping("listDevcie") @ApiOperation(value = "首页-首页设备查询") @ApiImplicitParams({ }) public Result listDevcie() { List result = topServcie.listDevcie(); return Result.OK(result); } @ApiOperation(value = "首页天气查询") @GetMapping("listWeather") @AutoLog(value = "首页天气查询") @ApiImplicitParams({ @ApiImplicitParam(name = "area", value = "地区", required = true, paramType = "query") }) public Result listWeather(@RequestParam(name = "area", required = false) String area) { JSONObject jsonObject = null; if (redisUtil.hasKey(area)) { return Result.OK(redisUtil.get(area)); } Map headers = new HashMap(); headers.put("Authorization", "APPCODE " + CommonConstant.TOP_WEATHER_APPCODE); Map querys = new HashMap(); querys.put("area", area); try { HttpResponse response = HttpUtils.doGet(CommonConstant.TOP_WEATHER_HOST, CommonConstant.TOP_WEATHER_PATH, CommonConstant.TOP_WEATHER_METHOD, headers, querys); HttpEntity entity = response.getEntity(); if (null != entity) { String s = EntityUtils.toString(response.getEntity()); jsonObject = JSONObject.parseObject(s); redisUtil.set(area, jsonObject, 60 * 60 * 6); } } catch (Exception e) { e.printStackTrace(); } return Result.OK(jsonObject); } @ApiOperation(value = "首页-液位查询") @GetMapping("listYw") @ApiImplicitParams({ @ApiImplicitParam(name = "devId", value = "设备id", required = false, paramType = "query") }) public Result listYw(@RequestParam(name = "devId", required = false, defaultValue = "861050040560321") String devId) { List tbDeviceInfoDTOS = topServcie.listYw(devId); return Result.OK(tbDeviceInfoDTOS); } @ApiOperation(value = "首页-历史告警查询") @GetMapping("listHistryAlarms") @ApiImplicitParams({ @ApiImplicitParam(name = "devId", value = "设备id", required = false, paramType = "query"), @ApiImplicitParam(name = "pageNo", value = "当前页 默认1", required = false, paramType = "query"), @ApiImplicitParam(name = "status", value = "告警状态", required = false, paramType = "query"), @ApiImplicitParam(name = "serial", value = "告警类型", required = false, paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "页数据条数20", required = false, paramType = "query") }) public Page listHistryAlarms( @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "status", required = false) String status, @RequestParam(name = "serial", required = false) String serial, @RequestParam(name = "devId", required = false) String devId ) { Page result = topServcie.listHistryAlarms(devId, pageSize, pageNo, status, serial); return result; } @ApiOperation(value = "历史告警统计") @GetMapping("listHistryAlarmsTj") @ApiImplicitParams({ }) public Result listHistryAlarmsTj( ) { Map result = topServcie.listHistryAlarmsTj(); return Result.OK(result); } @ApiOperation(value = "告警处理") @PostMapping("updateAlarm") @ApiImplicitParams({ @ApiImplicitParam(name = "Id", value = "告警编号", required = true, paramType = "query") }) public Result updateAlarm( @RequestParam(name = "Id") Integer Id ) { return topServcie.updateAlarm(Id); } }