fixed query dates params of access log filter

This commit is contained in:
kunw 2016-02-19 12:34:18 +08:00
parent 90aef78b1b
commit fd8c7a6405
4 changed files with 37 additions and 18 deletions

View File

@ -162,10 +162,14 @@ func (p *ProjectAPI) FilterAccessLog() {
username := filter.Username
keywords := filter.Keywords
beginTime := filter.BeginTime
endTime := filter.EndTime
query := models.AccessLog{ProjectId: p.projectId, Username: "%" + username + "%", Keywords: keywords, BeginTime: beginTime, EndTime: endTime}
beginTime := time.Unix(filter.BeginTimestamp, 0)
endTime := time.Unix(filter.EndTimestamp, 0)
query := models.AccessLog{ProjectId: p.projectId, Username: "%" + username + "%", Keywords: keywords, BeginTime: beginTime, BeginTimestamp: filter.BeginTimestamp, EndTime: endTime, EndTimestamp: filter.EndTimestamp}
log.Printf("Query AccessLog: begin: %v, end: %v, keywords: %s", query.BeginTime, query.EndTime, query.Keywords)
accessLogList, err := dao.GetAccessLogs(query)
if err != nil {
log.Printf("Error occurred in GetAccessLogs: %v", err)

View File

@ -73,13 +73,13 @@ func GetAccessLogs(accessLog models.AccessLog) ([]models.AccessLog, error) {
}
}
}
if accessLog.BeginTime != "" {
sql += ` and a.op_time >= str_to_date(?, '%Y-%m-%d %H:%i:%s') `
queryParam = append(queryParam, accessLog.BeginTime+" 00:00:00.000000")
if accessLog.BeginTimestamp > 0 {
sql += ` and a.op_time >= ? `
queryParam = append(queryParam, accessLog.BeginTime)
}
if accessLog.EndTime != "" {
sql += ` and a.op_time <= str_to_date(?, '%Y-%m-%d %H:%i:%s') `
queryParam = append(queryParam, accessLog.EndTime+" 23:59:59.99999")
if accessLog.EndTimestamp > 0 {
sql += ` and a.op_time <= ? `
queryParam = append(queryParam, accessLog.EndTime)
}
sql += ` order by a.op_time desc `

View File

@ -26,10 +26,11 @@ type AccessLog struct {
Guid string
Operation string
OpTime time.Time
OpTimeStr string
Username string
Keywords string
BeginTime string
EndTime string
BeginTime time.Time
BeginTimestamp int64
EndTime time.Time
EndTimestamp int64
}

View File

@ -374,24 +374,38 @@ jQuery(function(){
listUser(username);
});
function toUTCSeconds(date, hour, min, sec) {
var t = new Date(date);
t.setHours(hour);
t.setMinutes(min);
t.setSeconds(sec);
var utcTime = new Date(t.getUTCFullYear(),
t.getUTCMonth(),
t.getUTCDate(),
t.getUTCHours(),
t.getUTCMinutes(),
t.getUTCSeconds());
return utcTime.getTime() / 1000;
}
$("#btnFilterLog").on("click", function(){
var projectId = $("#projectId").val();
var username = $("#txtSearchUserName").val();
var beginTime = "";
var endTime = "";
var beginTimestamp = 0;
var endTimestamp = 0;
if($("#begindatepicker").val() != ""){
beginTime = moment(new Date($("#begindatepicker").val())).format("YYYY-MM-DD");
beginTimestamp = toUTCSeconds($("#begindatepicker").val(), 0, 0, 0);
}
if($("#enddatepicker").val() != ""){
endTime = moment(new Date($("#enddatepicker").val())).format("YYYY-MM-DD");
endTimestamp = toUTCSeconds($("#enddatepicker").val(), 23, 59, 59);
}
new AjaxUtil({
url: "/api/projects/" + projectId + "/logs/filter",
data:{"username":username, "project_id" : projectId, "keywords" : getKeyWords() , "beginTime" : beginTime, "endTime" : endTime},
data:{"username":username, "project_id" : projectId, "keywords" : getKeyWords() , "beginTimestamp" : beginTimestamp, "endTimestamp" : endTimestamp},
type: "post",
success: function(data, status, xhr){
if(xhr && xhr.status == 200){