Search in sources :

Example 1 with Page

use of com.mendmix.common.model.Page in project jeesuite-libs by vakinge.

the class ESLogStorageProvider method convertPage.

private Page<ActionLog> convertPage(SearchResponse response, PageParams pageParam) {
    SearchHits hits = response.getHits();
    List<ActionLog> datas = new ArrayList<>();
    hits.forEach(e -> {
        datas.add(JsonUtils.toObject(e.getSourceAsString(), ActionLog.class));
    });
    Page<ActionLog> page = new Page<>(pageParam, hits.getTotalHits().value - 1, datas);
    return page;
}
Also used : ArrayList(java.util.ArrayList) Page(com.mendmix.common.model.Page) SearchHits(org.elasticsearch.search.SearchHits) ActionLog(com.mendmix.logging.integrate.ActionLog)

Example 2 with Page

use of com.mendmix.common.model.Page in project jeesuite-libs by vakinge.

the class PaginationHandler method onInterceptor.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object onInterceptor(InvocationVals invocation) throws Throwable {
    PageParams pageParams = invocation.getPageParam();
    if (pageParams == null)
        return null;
    final MappedStatement orignMappedStatement = invocation.getMappedStatement();
    if (!orignMappedStatement.getSqlCommandType().equals(SqlCommandType.SELECT))
        return null;
    if (invocation.getSql() == null) {
        List<Object> list = new ArrayList<>(1);
        list.add(new Page<Object>(invocation.getPageParam(), 0, null));
        return list;
    }
    final ResultHandler resultHandler = (ResultHandler) invocation.getArgs()[3];
    // 查询总数
    Long total = executeQueryCount(invocation, resultHandler);
    // 查询分页数据
    List<?> datas = executeQuery(invocation, resultHandler);
    Page<Object> page = new Page<Object>(pageParams, total, (List<Object>) datas);
    List<Page<?>> list = new ArrayList<Page<?>>(1);
    list.add(page);
    return list;
}
Also used : ArrayList(java.util.ArrayList) PageParams(com.mendmix.common.model.PageParams) Page(com.mendmix.common.model.Page) MappedStatement(org.apache.ibatis.mapping.MappedStatement) ResultHandler(org.apache.ibatis.session.ResultHandler)

Example 3 with Page

use of com.mendmix.common.model.Page in project jeesuite-libs by vakinge.

the class RequestLogBuilder method responseLogMessage.

@SuppressWarnings("rawtypes")
public static String responseLogMessage(int statusCode, Object headers, Object body) {
    StringBuilder builder = new StringBuilder();
    builder.append("\n-----------response start-----------\n");
    builder.append("statusCode      :").append(statusCode).append("\n");
    if (body != null) {
        String bodyString;
        if (body instanceof byte[]) {
            byte[] bodyBytes = (byte[]) body;
            if (bodyBytes.length > 1024)
                bodyBytes = Arrays.copyOf(bodyBytes, 1024);
            bodyString = new String(bodyBytes);
        } else if (BeanUtils.isSimpleDataType(body)) {
            bodyString = body.toString();
        } else if (body instanceof Collection) {
            Collection bodyList = (Collection) body;
            bodyString = "itemNums:" + bodyList.size();
        } else if (body instanceof Page) {
            Page apge = (Page) body;
            bodyString = String.format("{\"pageNo\":%s,\"pageSize\":%s,\"total\":%s}", apge.getPageNo(), apge.getPageSize(), apge.getTotal());
        } else {
            bodyString = JsonUtils.toJson(body);
        }
        builder.append("body  :").append(bodyString).append("\n");
    }
    builder.append("-----------response end-----------\n");
    return builder.toString();
}
Also used : Collection(java.util.Collection) Page(com.mendmix.common.model.Page)

Aggregations

Page (com.mendmix.common.model.Page)3 ArrayList (java.util.ArrayList)2 PageParams (com.mendmix.common.model.PageParams)1 ActionLog (com.mendmix.logging.integrate.ActionLog)1 Collection (java.util.Collection)1 MappedStatement (org.apache.ibatis.mapping.MappedStatement)1 ResultHandler (org.apache.ibatis.session.ResultHandler)1 SearchHits (org.elasticsearch.search.SearchHits)1