var Service = require('Service');
var util = require('util');
var LogDao = require('../../dao/log_request');

/**
 * 获得日志列表
 */
var GetList = function() { 
  Service.call(this);
};

util.inherits(GetList, Service);

module.exports = GetList;

/**
 * 处理服务请求
 * @param  {Object} req 服务请求对象
 * @param  {Object} res 服务响应对象
 */
GetList.prototype.process =  function(req, res) {
  var where = 'path not like "sys/log/%"';
  if(req.startTime) where += ' and req_time>="'+req.startTime+' 0:00:00"';
  if(req.endTime) where += ' and req_time<="'+req.endTime+' 23:59:59"';
  if(req.keyword) {
    where += ' and (type like "%'+req.keyword+'%" or ip like "%'+req.keyword
    	+'%" or response_message like "%'+req.keyword
      +'%" or path like "%'+req.keyword+'%")';
  }
  var self = this;
  var logDao = new LogDao(this);
  logDao.queryDataPage(req, {where:where, order: 'id desc'}, function(dataPage){
  	res.dataPage = dataPage;
    self.emit('end', res);
  });
};