HostInfoCtrl.java
4.98 KB
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
package com.ui.ctrl;
import com.alibaba.fastjson.JSON;
import com.ui.common.TagTypeEnum;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.HostInfoReq;
import com.ui.model.req.SetHostTagsReq;
import com.ui.model.req.TagReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by yoho on 2016/6/14.
* 查询机器信息
*/
@Controller
@RequestMapping("/hostInfoList")
public class HostInfoCtrl {
Logger log = LoggerFactory.getLogger(HostInfoCtrl.class);
@Autowired
HttpRestClient httpRestClient;
@RequestMapping("/toHostInfos")
public ModelAndView toHostInfos() {
ModelAndView mv = new ModelAndView();
mv.setViewName("host/hostInfoList");
mv.addObject("tagTypeList", TagTypeEnum.getAllType());
mv.addObject("tagsListJson", this.getHostTagsByType("","groupName").getData());
return mv;
}
/**
* 根据标签类别,查询该类别下的属于tag
* @param type
* @return
*/
@RequestMapping("/getHostTagsByType")
@ResponseBody
public BaseResponse getHostTagsByType(String type,String idMark){
if(type==null){
type="";
}
TagReq req=new TagReq();
req.setTagTypeContent(type);
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.HOST_ALL_GROUPS, req, BaseResponse.class);
List<Map<String, String>> hostGroups = (List<Map<String, String>>) response.getData();
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
if (hostGroups != null && hostGroups.size() > 0) {
for (Map<String, String> m : hostGroups) {
HashMap map = new HashMap();
map.put("text", m.get("groupName"));
if("groupName".equals(idMark)){
map.put("id", m.get("groupName"));
}else{
map.put("id", m.get("id"));
}
tags.add(map);
}
}
return new BaseResponse<>(JSON.toJSON(tags));
}
@RequestMapping("/toEditHostInfos")
public ModelAndView toEditHostInfos(Map model) {
model.put("tagTypeMapJson", JSON.toJSONString(TagTypeEnum.getAllTypeMap()));
return new ModelAndView("host/editHostInfo",model);
}
@RequestMapping("/getHostInfos")
@ResponseBody
public BaseResponse getHostInfos(HostInfoReq req) throws Exception {
List<String> tagsList = JSON.parseArray(req.getTags(), String.class);
req.setTagsList(tagsList);
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.GET_HOST_INFOS, req, BaseResponse.class);
return response;
}
@RequestMapping("/saveHostInfo")
@ResponseBody
public BaseResponse saveHostInfo(HostInfoReq req) throws Exception {
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.SAVE_HOST_INFOS, req, BaseResponse.class);
return response;
}
@RequestMapping("/delHostInfo")
@ResponseBody
public BaseResponse<Integer> delHostInfo(int id,String hostIp) throws Exception {
//hostIp ,用作日志
Map<String, Object> map=new HashMap<>();
map.put("id",id);
map.put("hostIp",hostIp);
BaseResponse response = httpRestClient.defaultGet(HttpUriContants.DEL_HOST_INFOS + "?id=" + id, BaseResponse.class);
return response;
}
@RequestMapping("/getHostInfoById")
@ResponseBody
public BaseResponse getHostInfoById(int id) throws Exception {
BaseResponse response = httpRestClient.defaultGet(HttpUriContants.GET_HOST_INFO_BY_ID + "?id=" + id, BaseResponse.class);
return response;
}
@RequestMapping("/synHostInfo")
@ResponseBody
public BaseResponse synHostInfo() throws Exception {
BaseResponse response = httpRestClient.defaultGet(HttpUriContants.SYN_HOST_INFOS, BaseResponse.class);
return response;
}
@RequestMapping("/toSetHostTags")
public ModelAndView toSetHostTags(String hostIds) {
ModelAndView mv = new ModelAndView("host/setHostTags");
mv.addObject("tagTypeMapJson", JSON.toJSONString(TagTypeEnum.getAllTypeMap()));
return mv;
}
/**
* 备注--参数传递乱码,所以定义了一个SetHostTagsReq类
*
* @param req
* @return
*/
@RequestMapping("/saveHostTags")
@ResponseBody
public BaseResponse saveHostTags(SetHostTagsReq req) {
BaseResponse response = httpRestClient.defaultPost(HttpUriContants.SAVE_HOST_TAGS, req, BaseResponse.class);
return response;
}
}