API调用次数加上根据userID查
This commit is contained in:
+47
-41
@@ -134,55 +134,61 @@ public class UsersController {
|
|||||||
return json.toString();
|
return json.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object surplusCallCountAction() throws IllegalAccessException {
|
public Object surplusCallCountAction(ApiUserModel model) throws IllegalAccessException {
|
||||||
RestfulModelAndView mav = new RestfulModelAndView();
|
RestfulModelAndView mav = new RestfulModelAndView();
|
||||||
ActionContext context = ActionContext.getContext();
|
ActionContext context = ActionContext.getContext();
|
||||||
HttpServletRequest request = context.getRequest();
|
HttpServletRequest request = context.getRequest();
|
||||||
AuthenticationBean instance = (AuthenticationBean) request.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
|
AuthenticationBean instance = (AuthenticationBean) request.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
|
||||||
|
User user = null;
|
||||||
|
if (model.getUserId() != null && model.getUserId() > 0) {
|
||||||
|
user = userService.findById(model.getUserId());
|
||||||
|
}
|
||||||
if (null != instance) {
|
if (null != instance) {
|
||||||
User user = instance.user;
|
user = instance.user;
|
||||||
List<OpenResource> openResourceList = openResourceService.findAll();
|
}
|
||||||
List<ApiMonitorInfo> list = new ArrayList<ApiMonitorInfo>();
|
if (null == instance && user == null) {
|
||||||
long id = user.getId();
|
mav.setModel(new BasicModel(HttpStatusCodeEnum.BAD_REQUEST_ERROR_KEY));
|
||||||
ApiUserAuthority authority = apiUserAuthorityService.findByUserId(id);
|
return mav;
|
||||||
if (null != authority) {
|
}
|
||||||
// 用户有的uri
|
List<OpenResource> openResourceList = openResourceService.findAll();
|
||||||
List<OpenResource> userResources = new ArrayList<OpenResource>();
|
List<ApiMonitorInfo> list = new ArrayList<ApiMonitorInfo>();
|
||||||
for (OpenResource openResource : openResourceList) {
|
long id = user.getId();
|
||||||
if (authority.getOpenResourseUris().contains(openResource.getUri())) {
|
ApiUserAuthority authority = apiUserAuthorityService.findByUserId(id);
|
||||||
userResources.add(openResource);
|
if (null != authority) {
|
||||||
}
|
// 用户有的uri
|
||||||
}
|
List<OpenResource> userResources = new ArrayList<OpenResource>();
|
||||||
Map<String, Integer> countMap = authority.getTotalCountMap();
|
for (OpenResource openResource : openResourceList) {
|
||||||
if (null != countMap) {
|
if (authority.getOpenResourseUris().contains(openResource.getUri())) {
|
||||||
// 改成遍历用户有的uri
|
userResources.add(openResource);
|
||||||
for (OpenResource openResource : userResources) {
|
}
|
||||||
String uri = openResource.getUri();
|
}
|
||||||
ApiMonitorInfo info = new ApiMonitorInfo();
|
Map<String, Integer> countMap = authority.getTotalCountMap();
|
||||||
info.setApiUri(uri);
|
if (null != countMap) {
|
||||||
info.setApiName(openResource.getName());
|
// 改成遍历用户有的uri
|
||||||
info.setUserId((int) id);
|
for (OpenResource openResource : userResources) {
|
||||||
info.setUsername(user.getUserName());
|
String uri = openResource.getUri();
|
||||||
if (null != countMap.get(uri) && countMap.get(uri) > 0) {
|
ApiMonitorInfo info = new ApiMonitorInfo();
|
||||||
long curVistedCount = apiVisitCountService.findApiVisitCountByDay(id, uri, DateUtil.truncateDay(new Date()));
|
info.setApiUri(uri);
|
||||||
long historyCount = apiVisitCountService.findApiVisitAllCount(id, uri, DateUtil.truncateDay(new Date()));
|
info.setApiName(openResource.getName());
|
||||||
Integer totalCount = countMap.get(uri);
|
info.setUserId((int) id);
|
||||||
info.setTotalCallCount(Long.valueOf(totalCount));
|
info.setUsername(user.getUserName());
|
||||||
long usedCount = curVistedCount + historyCount;
|
if (null != countMap.get(uri) && countMap.get(uri) > 0) {
|
||||||
info.setSurplusCallCount(totalCount - usedCount);
|
long curVistedCount = apiVisitCountService.findApiVisitCountByDay(id, uri, DateUtil.truncateDay(new Date()));
|
||||||
info.setUsedCallCount(usedCount);
|
long historyCount = apiVisitCountService.findApiVisitAllCount(id, uri, DateUtil.truncateDay(new Date()));
|
||||||
}
|
Integer totalCount = countMap.get(uri);
|
||||||
list.add(info);
|
info.setTotalCallCount(Long.valueOf(totalCount));
|
||||||
|
long usedCount = curVistedCount + historyCount;
|
||||||
}
|
info.setSurplusCallCount(totalCount - usedCount);
|
||||||
|
info.setUsedCallCount(usedCount);
|
||||||
|
}
|
||||||
|
list.add(info);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BasicModel basicModel = new BasicModel(200, "ok");
|
|
||||||
basicModel.setResult(list);
|
|
||||||
mav.setModel(basicModel);
|
|
||||||
} else {
|
|
||||||
mav.setModel(new BasicModel(HttpStatusCodeEnum.BAD_REQUEST_ERROR_KEY));
|
|
||||||
}
|
}
|
||||||
|
BasicModel basicModel = new BasicModel(200, "ok");
|
||||||
|
basicModel.setResult(list);
|
||||||
|
mav.setModel(basicModel);
|
||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user