package com.moral.monitor.service.impl;
|
|
import java.text.ParseException;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.time.DateUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.moral.monitor.dao.HistoryEntityMapper;
|
import com.moral.monitor.service.ReportService;
|
import com.moral.monitor.util.BusinessException;
|
|
@Service
|
public class ReportServiceImpl implements ReportService {
|
|
@Autowired
|
private HistoryEntityMapper historyMapper;
|
|
@Override
|
public List<Map<String, Object>> getSensorsAverageByEquipment(Map<String, Object> parameters) {
|
Object type = parameters.get("type");
|
if ("hour".equals(type)) {
|
parameters.put("type", "%Y-%m-%d %H");
|
} else if ("minute".equals(type)) {
|
parameters.put("type", "%Y-%m-%d %H:%i");
|
} else {
|
throw new BusinessException("type参数输入错误!");
|
}
|
|
try {
|
Date start = DateUtils.parseDate((String)parameters.get("time"), "yyyy-MM-dd");
|
parameters.put("start", start);
|
parameters.put("end", DateUtils.addDays(start, 1));
|
} catch (ParseException e) {
|
e.printStackTrace();
|
throw new BusinessException("time参数输入错误!");
|
}
|
|
return historyMapper.getSensorsAverageByEquipment(parameters);
|
}
|
|
}
|