package com.whyc.webService;
|
|
import com.whyc.pojo.PageParam2;
|
import com.whyc.service.PageParam2Service;
|
import com.whyc.service.UserLogService;
|
import com.whyc.service.UserService;
|
import com.whyc.util.DateUtil;
|
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.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;
|
|
@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<>();
|
for (int i = 0; i < 2; i++) {
|
UserInfo userInfo = new UserInfo();
|
userInfo.setName("whyc");
|
userInfo.setLdapId("whyc");
|
userInfo.setSubCompany("whyc");
|
userInfo.setCorporation("whyc");
|
userInfo.setDepartment("whyc");
|
userInfo.setBureau("whyc");
|
userInfo.setIsLdapId(1);
|
userInfoList.add(userInfo);
|
}
|
result2.setUserInfoList(userInfoList);
|
return XmlParser.toXml2(result2);
|
|
}
|
else if(apiNameList.contains("BusinessSystemOnlineRoll")){
|
//单独调用,采用第二个返回值结构
|
|
}
|
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;
|
}
|
}
|
corporations.setApis(apisResponse);
|
|
|
return XmlParser.toXml(result);
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
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 String getStatus(String param) {
|
return null;
|
}
|
}
|