Merge pull request #2 from reasonerjt/fix_access_log_filter

fixed query dates params of access log filter
This commit is contained in:
reasonerjt 2016-02-22 10:32:47 +08:00
commit e62243a939
4 changed files with 37 additions and 18 deletions

View File

@ -162,10 +162,14 @@ func (p *ProjectAPI) FilterAccessLog() {
username := filter.Username username := filter.Username
keywords := filter.Keywords 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) accessLogList, err := dao.GetAccessLogs(query)
if err != nil { if err != nil {
log.Printf("Error occurred in GetAccessLogs: %v", err) 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 != "" { if accessLog.BeginTimestamp > 0 {
sql += ` and a.op_time >= str_to_date(?, '%Y-%m-%d %H:%i:%s') ` sql += ` and a.op_time >= ? `
queryParam = append(queryParam, accessLog.BeginTime+" 00:00:00.000000") queryParam = append(queryParam, accessLog.BeginTime)
} }
if accessLog.EndTime != "" { if accessLog.EndTimestamp > 0 {
sql += ` and a.op_time <= str_to_date(?, '%Y-%m-%d %H:%i:%s') ` sql += ` and a.op_time <= ? `
queryParam = append(queryParam, accessLog.EndTime+" 23:59:59.99999") queryParam = append(queryParam, accessLog.EndTime)
} }
sql += ` order by a.op_time desc ` sql += ` order by a.op_time desc `

View File

@ -26,10 +26,11 @@ type AccessLog struct {
Guid string Guid string
Operation string Operation string
OpTime time.Time OpTime time.Time
OpTimeStr string
Username string Username string
Keywords 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); 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(){ $("#btnFilterLog").on("click", function(){
var projectId = $("#projectId").val(); var projectId = $("#projectId").val();
var username = $("#txtSearchUserName").val(); var username = $("#txtSearchUserName").val();
var beginTime = ""; var beginTimestamp = 0;
var endTime = ""; var endTimestamp = 0;
if($("#begindatepicker").val() != ""){ if($("#begindatepicker").val() != ""){
beginTime = moment(new Date($("#begindatepicker").val())).format("YYYY-MM-DD"); beginTimestamp = toUTCSeconds($("#begindatepicker").val(), 0, 0, 0);
} }
if($("#enddatepicker").val() != ""){ if($("#enddatepicker").val() != ""){
endTime = moment(new Date($("#enddatepicker").val())).format("YYYY-MM-DD"); endTimestamp = toUTCSeconds($("#enddatepicker").val(), 23, 59, 59);
} }
new AjaxUtil({ new AjaxUtil({
url: "/api/projects/" + projectId + "/logs/filter", 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", type: "post",
success: function(data, status, xhr){ success: function(data, status, xhr){
if(xhr && xhr.status == 200){ if(xhr && xhr.status == 200){