付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
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
109
110
111
112
113
114
115
116
117
package com.wgcloud.service;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgcloud.dto.SubtitleDto;
import com.wgcloud.entity.HostDiskPer;
import com.wgcloud.mapper.HostDiskPerMapper;
import com.wgcloud.util.DateUtil;
import com.wgcloud.util.FormatUtil;
import com.wgcloud.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
 
import java.util.List;
import java.util.Map;
 
/**
 * @version v3.3
 * @ClassName:HostDiskPerService.java
 * @author: http://www.wgstart.com
 * @date: 2021年3月18日
 * @Description: HostDiskPerService.java
 * @Copyright: 2019-2021 wgcloud. All rights reserved.
 */
@Service
public class HostDiskPerService {
 
    public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
        PageHelper.startPage(currPage, pageSize);
        List<HostDiskPer> list = hostDiskPerMapper.selectByParams(params);
        PageInfo<HostDiskPer> pageInfo = new PageInfo<HostDiskPer>(list);
        return pageInfo;
    }
 
    public void save(HostDiskPer HostDiskPer) throws Exception {
        HostDiskPer.setId(UUIDUtil.getUUID());
        HostDiskPer.setCreateTime(DateUtil.getNowTime());
        hostDiskPerMapper.save(HostDiskPer);
    }
 
    @Transactional
    public void saveRecord(List<HostDiskPer> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        for (HostDiskPer as : recordList) {
            as.setId(UUIDUtil.getUUID());
        }
        hostDiskPerMapper.insertList(recordList);
    }
 
    public int deleteById(String[] id) throws Exception {
        return hostDiskPerMapper.deleteById(id);
    }
 
    public HostDiskPer selectById(String id) throws Exception {
        return hostDiskPerMapper.selectById(id);
    }
 
    public List<HostDiskPer> selectAllByParams(Map<String, Object> params) throws Exception {
        return hostDiskPerMapper.selectAllByParams(params);
    }
 
    public int deleteByAccHname(List<String> recordList) throws Exception {
        return hostDiskPerMapper.deleteByAccHname(recordList);
    }
 
    public int deleteByAccountAndDate(Map<String, Object> map) throws Exception {
        return hostDiskPerMapper.deleteByAccountAndDate(map);
    }
 
    /**
     * 设置图表的副标题,磁盘使用率的最高、平均、最低值
     *
     * @param model
     * @param hostDiskPerList 磁盘使用率状态数据
     */
    public void setSubtitle(Model model, List<HostDiskPer> hostDiskPerList) {
        //磁盘使用率最高
        Double maxDiskPer = 0d;
        //磁盘使用率最低
        Double minDiskPer = 1000d;
        //磁盘使用率平均
        Double avgDiskPer = 0d;
        Double sumDiskPer = 0d;
 
        for (HostDiskPer hostDiskPer : hostDiskPerList) {
            if (null != hostDiskPer.getDiskSumPer()) {
                if (hostDiskPer.getDiskSumPer() > maxDiskPer) {
                    maxDiskPer = hostDiskPer.getDiskSumPer();
                }
                if (hostDiskPer.getDiskSumPer() < minDiskPer) {
                    minDiskPer = hostDiskPer.getDiskSumPer();
                }
                sumDiskPer += hostDiskPer.getDiskSumPer();
            }
        }
        if (hostDiskPerList.size() > 0) {
            avgDiskPer = sumDiskPer / hostDiskPerList.size();
        } else {
            minDiskPer = 0d;
        }
 
        SubtitleDto hostDiskPerSubtitleDto = new SubtitleDto();
        hostDiskPerSubtitleDto.setAvgValue(FormatUtil.formatDouble(avgDiskPer, 2) + "");
        hostDiskPerSubtitleDto.setMaxValue(maxDiskPer + "");
        hostDiskPerSubtitleDto.setMinValue(minDiskPer + "");
        model.addAttribute("hostDiskPerSubtitleDto", hostDiskPerSubtitleDto);
    }
 
    @Autowired
    private HostDiskPerMapper hostDiskPerMapper;
 
 
}