kongdeqiang
2022-12-16 daf6a95086087ec99232eea8b4648b7541881f7c
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
package com.wgcloud.controller;
 
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageInfo;
import com.wgcloud.config.CommonConfig;
import com.wgcloud.dto.NetIoStateDto;
import com.wgcloud.entity.*;
import com.wgcloud.service.*;
import com.wgcloud.util.*;
import com.wgcloud.util.staticvar.StaticKeys;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @version v3.3
 * @ClassName:SystemInfoController.java
 * @author: http://www.wgstart.com
 * @date: 2021年1月16日
 * @Description: 主机信息管理
 * @Copyright: 2019-2021 wgcloud. All rights reserved.
 */
@Controller
@RequestMapping("/systemInfo")
public class SystemInfoController {
 
 
    private static final Logger logger = LoggerFactory.getLogger(SystemInfoController.class);
 
 
    @Resource
    private SystemInfoService systemInfoService;
    @Resource
    private LogInfoService logInfoService;
    @Resource
    private DashboardService dashboardService;
    @Resource
    private CpuStateService cpuStateService;
    @Resource
    private DiskStateService diskStateService;
    @Resource
    private DeskIoService deskIoService;
    @Resource
    private DiskSmartService diskSmartService;
    @Resource
    private CpuTemperaturesService cpuTemperaturesService;
    @Resource
    private HostDiskPerService hostDiskPerService;
    @Resource
    private MemStateService memStateService;
    @Resource
    private NetIoStateService netIoStateService;
    @Resource
    private SysLoadStateService sysLoadStateService;
    @Resource
    private ExcelExportService excelExportService;
    @Resource
    private HostGroupService hostGroupService;
    @Resource
    private AccountInfoService accountInfoService;
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private CommonConfig commonConfig;
 
 
    private void testThread() {
        Runnable runnable = () -> {
            logger.info("SystemInfoController----------testThread");
        };
        ThreadPoolUtil.executor.execute(runnable);
    }
 
    /**
     * 数据开放接口,agent查询主机列表
     *
     * @param model
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "agentList")
    public String agentList(@RequestBody String paramBean) {
        JSONObject agentJsonObject = (JSONObject) JSONUtil.parse(paramBean);
        if (!tokenUtils.checkAgentToken(agentJsonObject)) {
            logger.error(StaticKeys.TOKEN_ERROR);
            return ResDataUtils.resetErrorJson(StaticKeys.TOKEN_ERROR);
        }
 
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            if (!StringUtils.isEmpty(agentJsonObject.getStr("hostname"))) {
                params.put("hostname", agentJsonObject.getStr("hostname").trim());
            }
            if (!StringUtils.isEmpty(agentJsonObject.getStr("account"))) {
                params.put("account", agentJsonObject.getStr("account").trim());
            }
            if (!StringUtils.isEmpty(agentJsonObject.getStr("orderBy"))) {
                params.put("orderBy", agentJsonObject.getStr("orderBy"));
                params.put("orderType", agentJsonObject.getStr("orderType"));
            }
            PageInfo<SystemInfo> pageInfo = systemInfoService.selectByParams(params, agentJsonObject.getInt("page"), agentJsonObject.getInt("pageSize"));
            //设置磁盘总使用率 begin
            Map<String, Object> paramsAppInfo = new HashMap<String, Object>();
            for (SystemInfo systemInfo1 : pageInfo.getList()) {
                paramsAppInfo.put("hostname", systemInfo1.getHostname());
                List<DiskState> deskStates = diskStateService.selectAllByParams(paramsAppInfo);
                HostUtil.setDiskSumPer(deskStates, systemInfo1);
            }
            //设置磁盘总使用率 end
            return ResDataUtils.resetSuccessJson(pageInfo);
        } catch (Exception e) {
            logger.error("agent获取主机列表信息错误", e);
            logInfoService.save("agent获取主机列表信息错误", e.toString(), StaticKeys.LOG_XTCZ);
            return ResDataUtils.resetErrorJson(e.toString());
        }
    }
 
    /**
     * 保存主机备注信息
     *
     * @param SystemInfo
     * @param model
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "save")
    public String saveSystemInfo(SystemInfo SystemInfo, Model model, HttpServletRequest request) {
        try {
            if (!StringUtils.isEmpty(SystemInfo.getId())) {
                SystemInfo ho = systemInfoService.selectById(SystemInfo.getId());
                ho.setRemark(SystemInfo.getRemark());
                systemInfoService.updateById(ho);
                logInfoService.save(HostUtil.getAccountByRequest(request).getAccount() + "修改主机备注:" + ho.getHostname(), "主机备注:" + ho.getRemark(), StaticKeys.LOG_XTCZ);
            }
 
 
        } catch (Exception e) {
            logger.error("保存主机备注信息错误", e);
            logInfoService.save("保存主机备注信息错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "redirect:/systemInfo/systemInfoList";
    }
 
    /**
     * 保存主机windows远程url信息
     *
     * @param SystemInfo
     * @param model
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "saveWinConsole")
    public String saveWinConsole(SystemInfo SystemInfo, Model model, HttpServletRequest request) {
        try {
            if (!StringUtils.isEmpty(SystemInfo.getId())) {
                SystemInfo ho = systemInfoService.selectById(SystemInfo.getId());
                ho.setWinConsole(SystemInfo.getWinConsole());
                systemInfoService.updateById(ho);
                logInfoService.save(HostUtil.getAccountByRequest(request).getAccount() + "修改主机服务:" + ho.getHostname(), "主机服务:" + ho.getWinConsole(), StaticKeys.LOG_XTCZ);
            }
 
        } catch (Exception e) {
            logger.error("保存主机服务url信息错误", e);
            logInfoService.save("保存主机主机服务url信息错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        return SystemInfo.getWinConsole();
    }
 
    /**
     * 保存主机列表页面需要隐藏的列名
     *
     * @param model
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "saveHostListHideCols")
    public String saveHostListHideCols(Model model, HttpServletRequest request) {
        try {
            // 主机列表页面需要隐藏的列,当前登录session有效
            String[] hostListHideCols = request.getParameterValues("hostListHideCols");
            if (null != hostListHideCols) {
                request.getSession().setAttribute(StaticKeys.HOST_LIST_HIDE_COLS_INFO, StringUtils.join(hostListHideCols, StaticKeys.SPLIT_DH));
            } else {
                request.getSession().setAttribute(StaticKeys.HOST_LIST_HIDE_COLS_INFO, "");
            }
        } catch (Exception e) {
            logger.error("保存主机列表需要隐藏的列错误", e);
            logInfoService.save("保存主机列表需要隐藏的列错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "redirect:/systemInfo/systemInfoList";
    }
 
    /**
     * 保存主机分组信息
     *
     * @param SystemInfo
     * @param model
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "saveGroupId")
    public String saveGroupId(Model model, HttpServletRequest request) {
        try {
            String ids = request.getParameter("ids");
            String groupId = request.getParameter("groupId");
            HostGroup hostGroup = hostGroupService.selectById(groupId);
            if (!StringUtils.isEmpty(ids)) {
                SystemInfo ho = null;
                for (String id : ids.split(",")) {
                    ho = systemInfoService.selectById(id);
                    if (!StringUtils.isEmpty(groupId)) {
                        ho.setGroupId(groupId);
                    } else {
                        ho.setGroupId("");
                        hostGroup = new HostGroup();
                    }
                    systemInfoService.updateById(ho);
                    logInfoService.save(HostUtil.getAccountByRequest(request).getAccount() + "设置主机分组:" + ho.getHostname() + "," + ho.getRemark(), "分组:" + hostGroup.getGroupName(), StaticKeys.LOG_XTCZ);
                }
            }
        } catch (Exception e) {
            logger.error("保存主机分组信息错误", e);
            logInfoService.save("保存主机分组信息错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "redirect:/systemInfo/systemInfoList";
    }
 
    /**
     * 根据条件查询host列表
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "systemInfoList")
    public String systemInfoList(SystemInfo systemInfo, Model model, HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        try {
            StringBuffer url = new StringBuffer();
            String hostname = null;
            if (!StringUtils.isEmpty(systemInfo.getHostname())) {
                hostname = systemInfo.getHostname();
                params.put("hostname", hostname.trim());
                url.append("&hostname=").append(hostname);
            }
            if (!StringUtils.isEmpty(systemInfo.getState())) {
                params.put("state", systemInfo.getState());
                url.append("&state=").append(systemInfo.getState());
            }
            if (!StringUtils.isEmpty(systemInfo.getAccount())) {
                params.put("account", systemInfo.getAccount());
                url.append("&account=").append(systemInfo.getAccount());
            }
            if (!StringUtils.isEmpty(systemInfo.getGroupId())) {
                params.put("groupId", systemInfo.getGroupId());
                url.append("&groupId=").append(systemInfo.getGroupId());
            }
            if (!StringUtils.isEmpty(systemInfo.getOrderBy())) {
                params.put("orderBy", systemInfo.getOrderBy());
                params.put("orderType", systemInfo.getOrderType());
                url.append("&orderBy=").append(systemInfo.getOrderBy());
                url.append("&orderType=").append(systemInfo.getOrderType());
            }
            if (request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
                url.append("&dashView=1");
            }
 
            //校验是否需要添加过滤用户查询条件
            HostUtil.addAccountquery(request, params);
 
            PageInfo<SystemInfo> pageInfo = systemInfoService.selectByParams(params, systemInfo.getPage(), systemInfo.getPageSize());
 
            //主机分组,若已经开启分组选项的话
            List<HostGroup> hostGroupList = new ArrayList<>();
            if (StaticKeys.TRUE_VAL.equals(commonConfig.getHostGroup())) {
                params.clear();
                params.put("groupType", StaticKeys.HOST_GROUP_1);
                hostGroupList = hostGroupService.selectAllByParams(params);
            }
 
            //成员账号列表,若已经开启成员账号选项的话
            if (StaticKeys.TRUE_VAL.equals(commonConfig.getUserInfoManage())) {
                params.clear();
                List<AccountInfo> accountInfoList = accountInfoService.selectAllByParams(params);
                model.addAttribute("accountList", accountInfoList);
            }
 
            //添加主机附加值
            systemInfoService.hostAddVal(pageInfo, hostGroupList);
 
            //若是公众看板页面,未登录时,IP脱敏显示
            if (request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
                systemInfoService.hideLeftIp(pageInfo, request);
            }
 
            PageUtil.initPageNumber(pageInfo, model);
            model.addAttribute("pageUrl", "/systemInfo/systemInfoList?1=1" + url.toString());
            model.addAttribute("page", pageInfo);
            model.addAttribute("systemInfo", systemInfo);
            model.addAttribute("hostGroupList", hostGroupList);
 
            // 主机列表页面需要隐藏的列,当前登录session有效,若没有设置,初始化为空
            if (null == request.getSession().getAttribute(StaticKeys.HOST_LIST_HIDE_COLS_INFO)) {
                request.getSession().setAttribute(StaticKeys.HOST_LIST_HIDE_COLS_INFO, "");
            }
 
        } catch (Exception e) {
            logger.error("查询主机列表错误", e);
            logInfoService.save("查询主机列表错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        if (request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
            return "dashView/list";
        } else {
            return "host/list";
        }
    }
 
    /**
     * 根据条件查询host列表,异步获取
     *
     * @param model
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "systemInfoListAjax")
    public String systemInfoListAjax(SystemInfo systemInfo, Model model, HttpServletRequest request) {
        Map<String, Object> params = new HashMap<String, Object>();
        try {
            List<SystemInfo> systemInfoList = systemInfoService.selectAllByParams(params);
            for (SystemInfo sys : systemInfoList) {
                if (StaticKeys.DOWN_STATE.equals(sys.getState())) {
                    sys.setHostname("<span  class='badge bg-danger'>" + FormatUtil.getString(sys.getHostname(), 20) + "</span>");
                }
                //用image字段暂存下内存使用率 begin
                if (sys.getMemPer() >= 90) {
                    sys.setImage("<span class='badge bg-danger'>" + sys.getMemPer() + "</span>");
                }
                if (sys.getMemPer() >= 70 && sys.getMemPer() < 90) {
                    sys.setImage("<span class='badge bg-warning'>" + sys.getMemPer() + "</span>");
                }
                if (sys.getMemPer() < 70) {
                    sys.setImage("<span class='badge bg-primary'>" + sys.getMemPer() + "</span>");
                }
                //用image字段暂存下内存使用率 end
 
                //用主机名称字段暂存下cpu使用率 begin
                if (sys.getCpuPer() >= 90) {
                    sys.setHostnameExt("<span class='badge bg-danger'>" + sys.getCpuPer() + "</span>");
                }
                if (sys.getCpuPer() >= 70 && sys.getCpuPer() < 90) {
                    sys.setHostnameExt("<span class='badge bg-warning'>" + sys.getCpuPer() + "</span>");
                }
                if (sys.getCpuPer() < 70) {
                    sys.setHostnameExt("<span class='badge bg-primary'>" + sys.getCpuPer() + "</span>");
                }
                //用主机名称字段暂存下cpu使用率 end
                sys.setRxbyt(FormatUtil.kbToM(sys.getRxbyt()) + "/s");
                sys.setTxbyt(FormatUtil.kbToM(sys.getTxbyt()) + "/s");
                //用主机备注字段暂存下时间戳
                sys.setRemark(DateUtil.getDateTimeString(sys.getCreateTime()));
            }
            return JSONUtil.toJsonStr(systemInfoList);
        } catch (Exception e) {
            logger.error("ajax查询主机列表错误", e);
            logInfoService.save("ajax查询主机列表错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "";
    }
 
 
    /**
     * 根据IP查询服务器详情信息
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "detail")
    public String hostDetail(Model model, HttpServletRequest request) {
        //服务器名称
        String id = request.getParameter("id");
        if (StringUtils.isEmpty(id)) {
            return "error/500";
        }
        try {
            SystemInfo systemInfo = systemInfoService.selectById(id);
            model.addAttribute("systemInfo", systemInfo);
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("hostname", systemInfo.getHostname());
            List<DiskState> deskStateList = diskStateService.selectAllByParams(params);
            model.addAttribute("deskStateList", deskStateList);
            List<DeskIo> deskIoList = deskIoService.selectAllByParams(params);
            model.addAttribute("deskIoList", deskIoList);
            List<DiskSmart> diskSmartList = diskSmartService.selectAllByParams(params);
            model.addAttribute("diskSmartList", diskSmartList);
            List<CpuTemperatures> cpuTemperaturesList = cpuTemperaturesService.selectAllByParams(params);
            model.addAttribute("cpuTemperaturesList", cpuTemperaturesList);
            List<HostDiskPer> hostDiskPerList = hostDiskPerService.selectAllByParams(params);
            // 设置图表的副标题,磁盘使用率的最高、平均、最低值
            hostDiskPerService.setSubtitle(model, hostDiskPerList);
            model.addAttribute("hostDiskPerList", JSONUtil.parseArray(hostDiskPerList));
 
            //若是公众看板页面,未登录时,IP脱敏显示
            if (request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
                systemInfoService.hideLeftIp(systemInfo, request);
            }
 
        } catch (Exception e) {
            logger.error("主机详细信息错误", e);
            logInfoService.save("主机详细信息错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        if (request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
            return "dashView/view";
        } else {
            return "host/view";
        }
 
    }
 
    /**
     * 删除主机
     *
     * @param id
     * @param model
     * @param request
     * @param redirectAttributes
     * @return
     */
    @RequestMapping(value = "del")
    public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
        String errorMsg = "删除主机信息错误";
        try {
            if (!StringUtils.isEmpty(request.getParameter("id"))) {
                String[] ids = request.getParameter("id").split(",");
                for (String id : ids) {
                    SystemInfo sys = systemInfoService.selectById(id);
                    logInfoService.save(HostUtil.getAccountByRequest(request).getAccount() + "删除主机:" + sys.getHostname(), "主机:" + sys.getRemark(), StaticKeys.LOG_XTCZ);
                }
                systemInfoService.deleteById(ids);
            }
        } catch (Exception e) {
            logger.error(errorMsg, e);
            logInfoService.save(errorMsg, e.toString(), StaticKeys.LOG_XTCZ);
        }
        return "redirect:/systemInfo/systemInfoList";
    }
 
 
    /**
     * 根据IP查询服务器图形报表
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "chart")
    public String hostChart(Model model, HttpServletRequest request) {
        String id = request.getParameter("id");
        String startTime = request.getParameter(StaticKeys.SEARCH_START_TIME);
        String endTime = request.getParameter(StaticKeys.SEARCH_END_TIME);
        String am = request.getParameter("am");
        if (StringUtils.isEmpty(id)) {
            logger.error("hostChart id is  null");
            return "error/500";
        }
        try {
            SystemInfo systemInfo = systemInfoService.selectById(id);
            model.addAttribute("systemInfo", systemInfo);
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("hostname", systemInfo.getHostname());
            dashboardService.setDateParam(am, startTime, endTime, params, model);
            model.addAttribute("amList", dashboardService.getAmList());
            List<CpuState> cpuStateList = cpuStateService.selectAllByParams(params);
            model.addAttribute("cpuStateList", JSONUtil.parseArray(cpuStateList));
            List<MemState> memStateList = memStateService.selectAllByParams(params);
            model.addAttribute("memStateList", JSONUtil.parseArray(memStateList));
            List<SysLoadState> sysLoadStateList = sysLoadStateService.selectAllByParams(params);
            model.addAttribute("sysLoadStateList", JSONUtil.parseArray(sysLoadStateList));
            systemInfoService.findLoadMaxVal(sysLoadStateList, model);
            List<NetIoState> netIoStateList = netIoStateService.selectAllByParams(params);
            List<NetIoStateDto> netIoStateDtoList = systemInfoService.toNetIoStateDto(netIoStateList);
            model.addAttribute("netIoStateList", JSONUtil.parseArray(netIoStateDtoList));
            systemInfoService.findNetIoStateBytMaxVal(netIoStateDtoList, model);
 
            // 设置图表的副标题,cpu和内存的最高、平均、最低值
            systemInfoService.setSubtitle(model, cpuStateList, memStateList);
 
            //若是公众看板页面,未登录时,IP脱敏显示
            if (request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
                systemInfoService.hideLeftIp(systemInfo, request);
            }
 
        } catch (Exception e) {
            logger.error("主机图形报表错误", e);
            logInfoService.save("主机图形报表错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
        if (request.getParameter(StaticKeys.DASH_VIEW_ACCOUNT) != null) {
            return "dashView/viewChart";
        } else {
            return "host/viewChart";
        }
    }
 
    /**
     * 根据IP查询服务器图形报表,导出excel
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "chartExcel")
    public void hostChartExcel(Model model, HttpServletRequest request, HttpServletResponse response) {
        String id = request.getParameter("id");
        String startTime = request.getParameter(StaticKeys.SEARCH_START_TIME);
        String endTime = request.getParameter(StaticKeys.SEARCH_END_TIME);
        String am = request.getParameter("am");
        if (StringUtils.isEmpty(id)) {
            return;
        }
        try {
            SystemInfo systemInfo = systemInfoService.selectById(id);
            model.addAttribute("systemInfo", systemInfo);
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("hostname", systemInfo.getHostname());
            dashboardService.setDateParam(am, startTime, endTime, params, model);
            excelExportService.exportExcel(params, response);
        } catch (Exception e) {
            logger.error("主机图形报表导出excel错误", e);
            logInfoService.save("主机图形报表导出excel错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
    }
 
 
    /**
     * 所有主机列表,导出excel
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "hostListExcel")
    public void hostListExcel(SystemInfo systemInfo, HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            if (!StringUtils.isEmpty(systemInfo.getState())) {
                params.put("state", systemInfo.getState());
            }
            if (!StringUtils.isEmpty(systemInfo.getGroupId())) {
                params.put("groupId", systemInfo.getGroupId());
            }
            if (!StringUtils.isEmpty(systemInfo.getOrderBy())) {
                params.put("orderBy", systemInfo.getOrderBy());
                params.put("orderType", systemInfo.getOrderType());
            }
 
            //校验是否添加过滤用户查询条件
            HostUtil.addAccountquery(request, params);
 
            PageInfo<SystemInfo> pageInfo = systemInfoService.selectByParams(params, 1, 5000);
 
            //主机分组
            params.clear();
            List<HostGroup> hostGroupList = hostGroupService.selectAllByParams(params);
 
            //添加主机附加值
            systemInfoService.hostAddVal(pageInfo, hostGroupList);
            excelExportService.exportHostListExcel(pageInfo.getList(), response);
        } catch (Exception e) {
            logger.error("所有主机列表导出excel错误", e);
            logInfoService.save("所有主机列表导出excel错误", e.toString(), StaticKeys.LOG_XTCZ);
        }
    }
 
 
}