工业级运维app手机api
xufenglei
2017-11-14 91e5d3d85c737b96b2c4a1994e2b861cc083453c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);
    }
 
}