123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- 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<String, Object> result = topServcie.listDeviceStatus();
- return Result.OK(result);
- }
- @GetMapping("listAlarmsSe")
- @ApiOperation(value = "首页-七日告警统计")
- @ApiImplicitParams({
- })
- public Result<?> listAlarmsSe() {
- List<Object> result = topServcie.listAlarmsSe();
- return Result.OK(result);
- }
- @GetMapping("listDevcie")
- @ApiOperation(value = "首页-首页设备查询")
- @ApiImplicitParams({
- })
- public Result<?> listDevcie() {
- List<TbDeviceVOTop> result = topServcie.listDevcie();
- return Result.OK(result);
- }
- @ApiOperation(value = "首页天气查询")
- @GetMapping("listWeather")
- @AutoLog(value = "首页天气查询")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "area", value = "地区", required = true, paramType = "query")
- })
- public Result<Object> listWeather(@RequestParam(name = "area", required = false) String area) {
- JSONObject jsonObject = null;
- if (redisUtil.hasKey(area)) {
- return Result.OK(redisUtil.get(area));
- }
- Map<String, String> headers = new HashMap<String, String>();
- headers.put("Authorization", "APPCODE " + CommonConstant.TOP_WEATHER_APPCODE);
- Map<String, String> querys = new HashMap<String, String>();
- 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<Object> listYw(@RequestParam(name = "devId", required = false, defaultValue = "861050040560321") String devId) {
- List<TbDeviceInfoDTO> 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<TbDeviceAlarmsVO> 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<TbDeviceAlarmsVO> 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);
- }
- }
|