|
|
|
@ -0,0 +1,106 @@
|
|
|
|
|
package cn.estsh.i3plus.core.apiservice.daoimpl;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.dao.ISysLogSystemDao;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.StringTool;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysLogOperate;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysLogSystem;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.mongodb.Block;
|
|
|
|
|
import com.mongodb.client.AggregateIterable;
|
|
|
|
|
import com.mongodb.client.MongoCursor;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.jasper.tagplugins.jstl.core.ForEach;
|
|
|
|
|
import org.bson.Document;
|
|
|
|
|
import org.bson.json.JsonMode;
|
|
|
|
|
import org.bson.json.JsonWriterSettings;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.mongodb.MongoDbFactory;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description :
|
|
|
|
|
* @Reference :
|
|
|
|
|
* @Author : yunhao
|
|
|
|
|
* @CreateDate : 2018-12-11 13:24
|
|
|
|
|
* @Modify:
|
|
|
|
|
**/
|
|
|
|
|
@Service
|
|
|
|
|
public class SysLogSystemDaoImpl implements ISysLogSystemDao {
|
|
|
|
|
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(SysLogSystemDaoImpl.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MongoDbFactory mongoDbFactory;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@ApiOperation(value = "查询时间段内平均请求耗时")
|
|
|
|
|
public Map<String, Object> querySysLogOperateAvgExecuteTime(String startTime, String endTime) {
|
|
|
|
|
List<String> dList = new ArrayList<>();
|
|
|
|
|
Block<Document> saveBlock = new Block<Document>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void apply(final Document document) {
|
|
|
|
|
dList.add(document.toJson());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Document sub_match = new Document();
|
|
|
|
|
sub_match.put("leaveTime", new Document("$gte", startTime).append("$lte", endTime));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Document sub_substr = new Document();
|
|
|
|
|
sub_substr.put("$substr", new Object[]{"$createDatetime", 0, 16});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Document sub_project = new Document();
|
|
|
|
|
sub_project.put("new_time_stamp", sub_substr);
|
|
|
|
|
sub_project.put("executeTime", 1);
|
|
|
|
|
|
|
|
|
|
Document sub_group = new Document();
|
|
|
|
|
sub_group.put("_id", "createDatetime");
|
|
|
|
|
sub_group.put("avg", new Document("$avg", "$executeTime"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Document match = new Document("$match", sub_match);
|
|
|
|
|
Document project = new Document("$project", sub_project);
|
|
|
|
|
Document group = new Document("$group", sub_group);
|
|
|
|
|
Document sort = new Document("$sort", new Document("_id", 1));
|
|
|
|
|
|
|
|
|
|
List<Document> aggregateList = new ArrayList<>();
|
|
|
|
|
aggregateList.add(match);
|
|
|
|
|
// aggregateList.add(project);
|
|
|
|
|
aggregateList.add(group);
|
|
|
|
|
aggregateList.add(sort);
|
|
|
|
|
|
|
|
|
|
AggregateIterable<Document> findIter = mongoDbFactory.getDb()
|
|
|
|
|
.getCollection(StringTool.toLowerCaseFirstOne(SysLogSystem.class.getSimpleName()))
|
|
|
|
|
.aggregate(aggregateList);
|
|
|
|
|
MongoCursor<Document> cursor = findIter.iterator();
|
|
|
|
|
while (cursor.hasNext()) {
|
|
|
|
|
Document item_doc = cursor.next();
|
|
|
|
|
int _id = item_doc.getInteger("_id", 0);
|
|
|
|
|
int avg = item_doc.getInteger("avg", 0);
|
|
|
|
|
System.out.println("_id:" + _id + "abg:" + avg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return packObjectListFromDocument(dList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> packObjectListFromDocument(List<String> dList) {
|
|
|
|
|
//将获取的document转为对象
|
|
|
|
|
List<SysLogOperate> resultList = new ArrayList<>();
|
|
|
|
|
// 设置为宽松模式
|
|
|
|
|
JsonWriterSettings jsonWriterSettings = JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build();
|
|
|
|
|
for (String d : dList) {
|
|
|
|
|
resultList.add(JSONObject.parseObject(d, SysLogOperate.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|