List「Map「String, Object」」 返回 {key:“x“,value:“y“,...}

  /**
   * 统计本周异常数据 return ByDay 按每天返回
   * @param strDate
   * @return
   */
  @GetMapping("/get-aa-status-week")
  public ResponseEntity<Message> statisDeviceStatusByWeek(String strDate) {
    Message message = new Message();
    try {
      if(null == strDate){
        strDate = getPastDate(6);
      }
      List<Map<String, Object>> deviceStatusMap = tagDeviceService.statusDeviceStatusByDate(strDate,2);
      message.setData(deviceStatusMap);
    } catch (Exception e){
      message.setCode(100001);
      message.setMessage("get-aa-status-week出错");
    }
    return new ResponseEntity<>(message, HttpStatus.OK);
  }
  /**
   * 获取过去第几天的日期
   *
   * @param past
   * @return
   */
  public String getPastDate(int past) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
    Date today = calendar.getTime();
    String result = sdf1.format(today);
    return result;
  }
 public  List<Map<String, Object>> statusDeviceStatusByDate(String strDate,int dayType) {
    int time = 3600*24;
    String sdf = "yyyy-MM-dd";
    if(1 == dayType){
       time = 3600;//当天按小时计算
       sdf = "yyyy-MM-dd HH:mm:ss";
    }if (2 == dayType){
       time = 3600*24;//本周按天计算
     sdf =  "yyyy-MM-dd";
    }
    String nowTime1 = sdf1.format(new Date());
    Long nowTime = Long.valueOf(dateTimeStamp(nowTime1, "yyyy-MM-dd HH:mm:ss"));
    Long startTime = Long.valueOf(dateTimeStamp(strDate, "yyyy-MM-dd HH:mm:ss"));
    List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();

    while (startTime <= nowTime) {
      Map<String, Object> m1 = new HashMap<String, Object>();
      Map<String, Object> mapValue = new HashMap<>();
      Map<String, Object> mapKey = new HashMap<>();
      Long beforTime = startTime;
      Long afterTime = beforTime + time;
      String a = timeStampDate(String.valueOf(beforTime), "yyyy-MM-dd HH:mm:ss");
      String b = timeStampDate(String.valueOf(afterTime), "yyyy-MM-dd HH:mm:ss");
//      int normal = tagDeviceAllRepository.findDeviceAllRecordeByHour(0, a, b);
//      int exception = tagDeviceAllRepository.findDeviceAllRecordeByHour(1, a, b);
      int warning = tagDeviceAllRepository.findDeviceAllRecordeByHour(2, a, b);
//      mapValue.put("normal", normal);
//      mapValue.put("exception", exception);
      String outTime = timeStampDate(String.valueOf(beforTime), sdf);
      mapValue.put("value", warning);
      m1.put("key", outTime);
      m1.put("value", warning);
      list1.add(m1);
      startTime = afterTime;
    }
    return list1;
  }
{
	"code": 100000,
	"data": [
		{
			"value": 0,
			"key": "2020-06-26"
		},
		{
			"value": 0,
			"key": "2020-06-27"
		},
		{
			"value": 0,
			"key": "2020-06-28"
		},
		{
			"value": 10,
			"key": "2020-06-29"
		},
		{
			"value": 11,
			"key": "2020-06-30"
		},
		{
			"value": 7,
			"key": "2020-07-01"
		},
		{
			"value": 0,
			"key": "2020-07-02"
		}
	],
	"message": "操作成功",
	"ret": 200
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值