工业级运维app手机api
xufenglei
2017-10-26 62a2c2cff2978dfcfe2fc4ef3e4c1e2a89835dbf
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.moral.monitor.service.impl;
 
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.moral.monitor.dao.AccountEntityMapper;
import com.moral.monitor.dao.HistoryEntityMapper;
import com.moral.monitor.entity.AccountEntity;
import com.moral.monitor.entity.AccountEntityExample;
import com.moral.monitor.service.OrganizationService;
import com.moral.monitor.service.ScreenService;
 
@Service
public class ScreenServiceImpl implements ScreenService {
 
    @Autowired
    private AccountEntityMapper accountMapper;
 
    @Autowired
    private HistoryEntityMapper historyMapper;
 
    @Autowired
    private OrganizationService organizationService;
 
    public List<AccountEntity> getAccountLists(String account, String password) {
        AccountEntityExample example = new AccountEntityExample();
        example.or().andAccountEqualTo(account).andPasswordEqualTo(password);
        return accountMapper.selectByExample(example);
    }
 
    @SuppressWarnings("deprecation")
    public Map<String, Object> getDataByEquipmentMac(Map<String, Object> parameters) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Date date = new Date();
 
        /** 临时代码 以保证查询有数据 **/
        date.setMonth(6);
        int day = date.getDate();
        if (day < 13) {
            day = 31 - day;
        }else if (day < 19) {
            day += 10;
        }else if (day > 29) {
            day -= 10;
        }
        date.setDate(day);
        /** 临时代码 结束 **/
 
        parameters.put("end", DateUtils.truncate(date, Calendar.DATE));
        
        //每月一日的数据取上月的数据
        /*if (1 == Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) {
            date = DateUtils.setMonths(date, -1);
            parameters.put("end", DateUtils.ceiling(date, Calendar.MONTH));
        }*/
        parameters.put("start", DateUtils.truncate(date, Calendar.MONTH));
        parameters.put("mac", "898602b8191630065884");
        parameters.put("macKey", "e1");
        Map<String, Object> monthAverageBySensor = historyMapper.getMonthAverageBySensor(parameters);
        if (MapUtils.isNotEmpty(monthAverageBySensor)) {
            resultMap.putAll(monthAverageBySensor);
        } else {
            resultMap.put("monthAverage", 0);
        }
        return resultMap;
    }
 
    @SuppressWarnings("deprecation")
    public Map<String, Object> getAverageByAll(Map<String, Object> parameters) {
 
        AccountEntity account = accountMapper.selectByPrimaryKey((Integer.valueOf((String) parameters.get("accountId"))));
        String organization = account.getOrganization();
        //不是摩瑞尔账号的需要根据组织来获取数据权限
        if (!("-1".equals(organization) || "5212b9dfb55448e699889e01fa0fa6a2".equals(organization))) {
            Set<String> orgIds = organizationService.getChildOrganizationIds(account.getOrganization());
            parameters.put("orgIds", orgIds);
        }
        Date date = new Date();
        
        /** 临时代码 以保证查询有数据 **/
        date.setMonth(6);
        int day = date.getDate();
        if (day < 19 || day > 29) {
            day = (int) Math.floor(Math.random() * (29 - 19 + 1) + 19);
            date.setDate(day);
        }
        /** 临时代码 结束 **/
 
        parameters.put("start", DateUtils.addMinutes(date, -10));
        parameters.put("end", DateUtils.addMinutes(date, -5));
        List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
        Map<String, Object> result = new HashMap<String, Object>();
        for (Map<String, Object> map : averageByAll) {
            result.put((String) map.get("mac_key"), map.get("avg"));
        }
        return result;
    }
 
}