TopController.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.usky.controller.top;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.usky.annotion.AutoLog;
  4. import com.usky.constant.CommonConstant;
  5. import com.usky.entity.mqtt.TbDeviceInfoDTO;
  6. import com.usky.entity.mqtt.vo.TbDeviceAlarmsVO;
  7. import com.usky.entity.mqtt.vo.TbDeviceInfoVO;
  8. import com.usky.entity.mqtt.vo.TbDeviceVO;
  9. import com.usky.entity.mqtt.vo.TbDeviceVOTop;
  10. import com.usky.service.top.TopServcie;
  11. import com.usky.utils.HttpUtils;
  12. import com.usky.utils.Page;
  13. import com.usky.utils.RedisUtil;
  14. import com.usky.utils.Result;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiImplicitParam;
  17. import io.swagger.annotations.ApiImplicitParams;
  18. import io.swagger.annotations.ApiOperation;
  19. import org.apache.http.HttpEntity;
  20. import org.apache.http.HttpResponse;
  21. import org.apache.http.util.EntityUtils;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.web.bind.annotation.*;
  24. import java.util.HashMap;
  25. import java.util.List;
  26. import java.util.Map;
  27. /**
  28. * @author laowo
  29. * @version v1.0
  30. * @date 2021/8/10 17:25
  31. * @description TODO
  32. **/
  33. @RestController
  34. @RequestMapping("jx/top")
  35. @Api(tags = "首页")
  36. public class TopController {
  37. @Autowired
  38. private TopServcie topServcie;
  39. @Autowired
  40. private RedisUtil redisUtil;
  41. @GetMapping("listDeviceStatus")
  42. @ApiOperation(value = "首页-设备状态统计")
  43. @ApiImplicitParams({
  44. })
  45. public Result<?> listDeviceStatus() {
  46. Map<String, Object> result = topServcie.listDeviceStatus();
  47. return Result.OK(result);
  48. }
  49. @GetMapping("listAlarmsSe")
  50. @ApiOperation(value = "首页-七日告警统计")
  51. @ApiImplicitParams({
  52. })
  53. public Result<?> listAlarmsSe() {
  54. List<Object> result = topServcie.listAlarmsSe();
  55. return Result.OK(result);
  56. }
  57. @GetMapping("listDevcie")
  58. @ApiOperation(value = "首页-首页设备查询")
  59. @ApiImplicitParams({
  60. })
  61. public Result<?> listDevcie() {
  62. List<TbDeviceVOTop> result = topServcie.listDevcie();
  63. return Result.OK(result);
  64. }
  65. @ApiOperation(value = "首页天气查询")
  66. @GetMapping("listWeather")
  67. @AutoLog(value = "首页天气查询")
  68. @ApiImplicitParams({
  69. @ApiImplicitParam(name = "area", value = "地区", required = true, paramType = "query")
  70. })
  71. public Result<Object> listWeather(@RequestParam(name = "area", required = false) String area) {
  72. JSONObject jsonObject = null;
  73. if (redisUtil.hasKey(area)) {
  74. return Result.OK(redisUtil.get(area));
  75. }
  76. Map<String, String> headers = new HashMap<String, String>();
  77. headers.put("Authorization", "APPCODE " + CommonConstant.TOP_WEATHER_APPCODE);
  78. Map<String, String> querys = new HashMap<String, String>();
  79. querys.put("area", area);
  80. try {
  81. HttpResponse response = HttpUtils.doGet(CommonConstant.TOP_WEATHER_HOST, CommonConstant.TOP_WEATHER_PATH, CommonConstant.TOP_WEATHER_METHOD, headers, querys);
  82. HttpEntity entity = response.getEntity();
  83. if (null != entity) {
  84. String s = EntityUtils.toString(response.getEntity());
  85. jsonObject = JSONObject.parseObject(s);
  86. redisUtil.set(area, jsonObject, 60 * 60 * 6);
  87. }
  88. } catch (Exception e) {
  89. e.printStackTrace();
  90. }
  91. return Result.OK(jsonObject);
  92. }
  93. @ApiOperation(value = "首页-液位查询")
  94. @GetMapping("listYw")
  95. @ApiImplicitParams({
  96. @ApiImplicitParam(name = "devId", value = "设备id", required = false, paramType = "query")
  97. })
  98. public Result<Object> listYw(@RequestParam(name = "devId", required = false, defaultValue = "861050040560321") String devId) {
  99. List<TbDeviceInfoDTO> tbDeviceInfoDTOS = topServcie.listYw(devId);
  100. return Result.OK(tbDeviceInfoDTOS);
  101. }
  102. @ApiOperation(value = "首页-历史告警查询")
  103. @GetMapping("listHistryAlarms")
  104. @ApiImplicitParams({
  105. @ApiImplicitParam(name = "devId", value = "设备id", required = false, paramType = "query"),
  106. @ApiImplicitParam(name = "pageNo", value = "当前页 默认1", required = false, paramType = "query"),
  107. @ApiImplicitParam(name = "status", value = "告警状态", required = false, paramType = "query"),
  108. @ApiImplicitParam(name = "serial", value = "告警类型", required = false, paramType = "query"),
  109. @ApiImplicitParam(name = "pageSize", value = "页数据条数20", required = false, paramType = "query")
  110. })
  111. public Page<TbDeviceAlarmsVO> listHistryAlarms(
  112. @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
  113. @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
  114. @RequestParam(name = "status", required = false) String status,
  115. @RequestParam(name = "serial", required = false) String serial,
  116. @RequestParam(name = "devId", required = false) String devId
  117. ) {
  118. Page<TbDeviceAlarmsVO> result = topServcie.listHistryAlarms(devId, pageSize, pageNo, status, serial);
  119. return result;
  120. }
  121. @ApiOperation(value = "历史告警统计")
  122. @GetMapping("listHistryAlarmsTj")
  123. @ApiImplicitParams({
  124. })
  125. public Result<?> listHistryAlarmsTj(
  126. ) {
  127. Map result = topServcie.listHistryAlarmsTj();
  128. return Result.OK(result);
  129. }
  130. @ApiOperation(value = "告警处理")
  131. @PostMapping("updateAlarm")
  132. @ApiImplicitParams({
  133. @ApiImplicitParam(name = "Id", value = "告警编号", required = true, paramType = "query")
  134. })
  135. public Result<?> updateAlarm( @RequestParam(name = "Id") Integer Id
  136. ) {
  137. return topServcie.updateAlarm(Id);
  138. }
  139. }