package com.whyc.webService;
|
|
import com.whyc.mapper.CommonMapper;
|
import com.whyc.pojo.PageParam2;
|
import com.whyc.service.BattInfService;
|
import com.whyc.service.PageParam2Service;
|
import com.whyc.service.UserService;
|
import com.whyc.util.DateUtil;
|
import com.whyc.util.SerialNumberUtil;
|
import com.whyc.webService.dto.request.Api;
|
import com.whyc.webService.dto.request.RequestParam;
|
import com.whyc.webService.dto.response.response1.Corporation;
|
import com.whyc.webService.dto.response.response1.ResponseResult;
|
import com.whyc.webService.dto.response.response2.ResponseResult2;
|
import com.whyc.webService.dto.response.response2.UserInfo;
|
import com.whyc.webService.util.XmlParser;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import javax.jws.WebService;
|
import javax.servlet.ServletContext;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Component
|
@WebService(targetNamespace = "http://service.webService.whyc.com/",
|
endpointInterface = "com.whyc.webService.IMS_Service")
|
public class IMS_ServiceImpl implements IMS_Service{
|
|
@Autowired
|
private UserService userService;
|
|
@Autowired
|
private PageParam2Service pageParam2Service;
|
|
@Resource
|
private CommonMapper commonMapper;
|
|
@Autowired
|
private BattInfService battInfService;
|
|
@Autowired
|
private ServletContext servletContext;
|
|
|
/**
|
*
|
* @param param xml格式的字符串
|
* @return xml格式的字符串
|
*/
|
@Override
|
public String getKPIValue(String param) {
|
try {
|
|
//解析传入参数
|
RequestParam requestParam = XmlParser.parseXmlRequest(param);
|
//地域代码,太供提供,作用不明
|
String corporationCode = requestParam.getCorporationCode();
|
//时间值,作用不明
|
String time = requestParam.getTime();
|
//指标
|
List<Api> apis = requestParam.getApis();
|
List<String> apiNameList = apis.stream().map(Api::getName).collect(Collectors.toList());
|
if (apiNameList.contains("BusinessSystemLoginRoll")) {
|
//单独调用,采用第二个返回值结构
|
ResponseResult2 result2 = new ResponseResult2();
|
List<UserInfo> userInfoList = new LinkedList<>();
|
result2.setUserInfoList(userInfoList);
|
HashMap<String, String> loginMap = (HashMap<String, String>) servletContext.getAttribute("login");
|
if(loginMap != null) {
|
String dateStr = DateUtil.YYYY_MM_DD.format(new Date());
|
loginMap.values().removeIf(aString -> !aString.equals(dateStr));
|
}
|
if (loginMap != null && loginMap.size() != 0) {
|
|
loginMap.keySet().forEach(key -> {
|
UserInfo userInfo = new UserInfo();
|
userInfo.setName(key);
|
userInfo.setLdapId(key);
|
//省公司名称或国家电网公司总部 TODO 这个要与tg的人确认
|
userInfo.setCorporation("-");
|
//地市公司名称
|
userInfo.setSubCompany("-");
|
//县级单位名称
|
userInfo.setBureau("-");
|
//部门名称
|
userInfo.setDepartment("-");
|
userInfo.setIsLdapId(0);
|
userInfoList.add(userInfo);
|
});
|
}
|
return XmlParser.toXml2(result2);
|
|
}
|
else if(apiNameList.contains("BusinessSystemOnlineRoll")){
|
//单独调用,采用第二个返回值结构
|
ResponseResult2 result2 = new ResponseResult2();
|
//统计更新时间在10秒钟内的
|
HashMap<String, Long> onlineMap = (HashMap<String, Long>) servletContext.getAttribute("online");
|
if(onlineMap != null) {
|
onlineMap.values().removeIf(aLong -> System.currentTimeMillis() - aLong > 10000);
|
}
|
if (onlineMap != null && onlineMap.size() != 0) {
|
List<UserInfo> userInfoList = new LinkedList<>();
|
onlineMap.keySet().forEach(key -> {
|
UserInfo userInfo = new UserInfo();
|
userInfo.setName(key);
|
userInfo.setLdapId(key);
|
//省公司名称或国家电网公司总部 TODO 这个要与tg的人确认
|
userInfo.setCorporation("-");
|
//地市公司名称
|
userInfo.setSubCompany("-");
|
//县级单位名称
|
userInfo.setBureau("-");
|
//部门名称
|
userInfo.setDepartment("-");
|
userInfo.setIsLdapId(0);
|
userInfoList.add(userInfo);
|
});
|
result2.setUserInfoList(userInfoList);
|
}
|
return XmlParser.toXml2(result2);
|
}
|
else {
|
//构建返回参数
|
ResponseResult result = new ResponseResult();
|
result.setStatus("success");
|
result.setMessage("success");
|
Corporation corporations = new Corporation();
|
corporations.setId(corporationCode);
|
result.setCorporation(corporations);
|
List<com.whyc.webService.dto.response.response1.Api> apisResponse = new LinkedList<>();
|
|
int size = apis.size();
|
for (int i = 0; i < size; i++) {
|
switch (apis.get(i).getName()) {
|
//1注册用户数
|
case "BusinessUserRegNum":
|
//查询用户表的记录数
|
getItem1(apisResponse);
|
break;
|
//2在线用户数
|
case "BusinessSystemOnlineNum":
|
getItem2(apisResponse);
|
break;
|
//3日登录用户数
|
case "BusinessDayLoginNum":
|
getItem3(apisResponse);
|
break;
|
//4累计访问人数
|
case "BusinessVisitCount":
|
getItem4(apisResponse);
|
break;
|
//5.页面会话连接数(对外提供的页面连接会话个数-暂无)
|
case "BusinessSystemSessionNum":
|
getItem5(apisResponse);
|
break;
|
//6.系统服务响应时长(页面调用的接口调用时长,界面配合)
|
case "BusinessSystemResponseTime":
|
getItem6(apisResponse);
|
break;
|
//7.系统健康运行时长
|
case "BusinessSystemRunningTime":
|
getItem7(apisResponse);
|
break;
|
//8.业务应用系统占用表空间大小(/app 和/var/lib/mysql)
|
case "BusinessDataTableSpace":
|
getItem8(apisResponse);
|
break;
|
//9数据库平均响应时长
|
//这里的逻辑是5分钟内响应的接口的历史所有次数统计的平均值(目前未查到系统表有相关历史sql的每个时间统计)
|
case "BusinessSystemDBTime":
|
getItem9(apisResponse);
|
break;
|
}
|
}
|
corporations.setApis(apisResponse);
|
|
|
return XmlParser.toXml(result);
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
private void getItem6(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
long startTime = System.currentTimeMillis();
|
battInfService.getStationIds();
|
long endTime = System.currentTimeMillis();
|
int timeGap = (int) (endTime - startTime);
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessSystemResponseTime");
|
apiResponse.setValue(timeGap);
|
apisResponse.add(apiResponse);
|
}
|
|
private static void getItem8(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
Integer dataTableSpace = SerialNumberUtil.getDataTableSpace();
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessDataTableSpace");
|
apiResponse.setValue(dataTableSpace);
|
apisResponse.add(apiResponse);
|
}
|
|
private void getItem9(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
Long systemDBTimeIn5Minutes = commonMapper.getSystemDBTimeIn5Minutes()/1000000000;
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessSystemDBTime");
|
apiResponse.setValue(systemDBTimeIn5Minutes.intValue());
|
apisResponse.add(apiResponse);
|
}
|
|
private void getItem7(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
Long systemStartTime = (Long) servletContext.getAttribute("system_start_time");
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessSystemRunningTime");
|
apiResponse.setValue((int) ((System.currentTimeMillis() - systemStartTime)/1000));
|
apisResponse.add(apiResponse);
|
}
|
|
private static void getItem5(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessUserRegNum");
|
apiResponse.setValue(0);
|
apisResponse.add(apiResponse);
|
}
|
|
private void getItem4(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
PageParam2 Param4visitCount = pageParam2Service.getById(5);
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessUserRegNum");
|
apiResponse.setValue(Integer.valueOf(Param4visitCount.getValue()));
|
apisResponse.add(apiResponse);
|
}
|
|
private void getItem3(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
HashMap<String, String> loginMap = (HashMap<String, String>) servletContext.getAttribute("login");
|
int loginQuantity = 0;
|
if(loginMap != null){
|
String dateStr = DateUtil.YYYY_MM_DD.format(new Date());
|
loginMap.values().removeIf(aString -> !aString.equals(dateStr));
|
loginQuantity = loginMap.size();
|
}
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessDayLoginNum");
|
apiResponse.setValue(loginQuantity);
|
apisResponse.add(apiResponse);
|
}
|
|
private void getItem2(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
HashMap<String, Long> onlineMap = (HashMap<String, Long>) servletContext.getAttribute("online");
|
//统计更新时间在10秒钟内的
|
int onlineQuantity = 0;
|
if(onlineMap != null){
|
onlineMap.values().removeIf(aLong -> System.currentTimeMillis() - aLong > 10000);
|
onlineQuantity = onlineMap.size();
|
}
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessSystemOnlineNum");
|
apiResponse.setValue(onlineQuantity);
|
apisResponse.add(apiResponse);
|
}
|
|
private void getItem1(List<com.whyc.webService.dto.response.response1.Api> apisResponse) {
|
int userQuantity = userService.getAll().size();
|
com.whyc.webService.dto.response.response1.Api apiResponse = new com.whyc.webService.dto.response.response1.Api();
|
apiResponse.setName("BusinessUserRegNum");
|
apiResponse.setValue(userQuantity);
|
apisResponse.add(apiResponse);
|
}
|
|
/**
|
*
|
* @param param
|
* @return
|
*/
|
@Override
|
public Integer getStatus(String param) {
|
return 1;
|
}
|
}
|