@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);
}
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 warning = tagDeviceAllRepository.findDeviceAllRecordeByHour(2, a, b);
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
}