use of org.mx.dal.Pagination in project main by JohnPeng739.
the class UserManageResource method listUsersPagination.
@Path("users")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<UserVO>> listUsersPagination(Pagination pagination) {
if (pagination == null) {
pagination = new Pagination();
}
try {
List<User> users = accessor.list(pagination, User.class);
List<UserVO> userVOs = UserVO.transform(users);
return new PaginationDataVO<>(pagination, userVOs);
} catch (UserInterfaceException ex) {
return new PaginationDataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("List users fail.", ex);
}
return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.dal.Pagination in project main by JohnPeng739.
the class GeneralAccessorImpl method list.
/**
* {@inheritDoc}
*
* @see GeneralAccessor#list(Pagination, Class, boolean)
*/
@Override
public <T extends Base> List<T> list(Pagination pagination, Class<T> clazz, boolean isValid) {
if (pagination == null) {
pagination = new Pagination();
}
try {
if (clazz.isInterface()) {
clazz = EntityFactory.getEntityClass(clazz);
}
pagination.setTotal((int) count(clazz, isValid));
int skip = (pagination.getPage() - 1) * pagination.getSize();
int limit = pagination.getSize();
if (isValid) {
return template.find(query(where("valid").is(true)).skip(skip).limit(limit), clazz);
} else {
return template.find(new Query().skip(skip).limit(limit), clazz);
}
} catch (ClassNotFoundException ex) {
throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.ENTITY_INSTANCE_FAIL);
}
}
use of org.mx.dal.Pagination in project main by JohnPeng739.
the class NotifyServerResource method getOnlineDevices.
/**
* 获取符合条件的在线设备列表
*
* @param state 指定的状态
* @param later 注册时间晚于指定时间
* @param early 注册时间早于指定时间
* @param pagination 分页对象
* @return 在线设备列表
*/
@Path("onlines")
@POST
public PaginationDataVO<List<OnlineDeviceVO>> getOnlineDevices(@QueryParam("state") String state, @QueryParam("later") long later, @QueryParam("early") long early, Pagination pagination) {
List<Predicate<OnlineDevice>> filters = new ArrayList<>();
if (!StringUtils.isBlank(state)) {
filters.add(onlineDevice -> state.equals(onlineDevice.getState()));
}
if (later > 0) {
filters.add(onlineDevice -> onlineDevice.getRegistryTime() >= later);
}
if (early > 0) {
filters.add(onlineDevice -> onlineDevice.getRegistryTime() <= early);
}
Set<OnlineDevice> set = onlineManager.getOnlineDevices(filters);
if (pagination == null) {
pagination = new Pagination();
}
List<OnlineDevice> list = new ArrayList<>();
list.addAll(set);
// 按照注册时间排序
list.sort((od1, od2) -> (int) (od1.getRegistryTime() - od2.getRegistryTime()));
pagination.setTotal(set.size());
List<OnlineDevice> result = new ArrayList<>();
int skip = (pagination.getPage() - 1) * pagination.getSize();
int num = Math.min(pagination.getSize(), list.size() - skip);
for (int index = skip; index < skip + num; index++) {
result.add(list.get(index));
}
return new PaginationDataVO<>(pagination, OnlineDeviceVO.transform(result));
}
use of org.mx.dal.Pagination in project main by JohnPeng739.
the class ServerManageResource method getServers.
@Path("servers")
@POST
public PaginationDataVO<List<ServerInfoVO>> getServers(Pagination pagination) {
if (pagination == null) {
pagination = new Pagination();
}
try {
Map<String, JSONObject> map = serverManageService.getServerInfos(pagination);
List<ServerInfoVO> list = new ArrayList<>();
map.values().forEach(json -> list.add(new ServerInfoVO(json)));
return new PaginationDataVO<>(pagination, list);
} catch (UserInterfaceErrorException ex) {
return new PaginationDataVO<>(ex);
}
}
use of org.mx.dal.Pagination in project main by JohnPeng739.
the class AccountManageResource method logs.
@Path("logs")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<OperateLogVO>> logs(Pagination pagination, @Context Request request) {
if (pagination == null) {
pagination = new Pagination();
}
try {
List<OperateLog> logs = accessor.list(pagination, OperateLog.class);
List<OperateLogVO> vos = OperateLogVO.transform(logs);
return new PaginationDataVO(pagination, vos);
} catch (UserInterfaceException ex) {
return new PaginationDataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("List logs fail.", ex);
}
return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
Aggregations