package com.lightinit.hsdataplatform.impl;

import com.lightinit.hsdataplatform.entity.MTLogInfo;
import com.lightinit.hsdataplatform.service.IMTLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

/**
 * Created by herbert on 2017/10/20.
 */
@Service
public class MTLogServiceImpl implements IMTLogService {

    /*@Autowired
    private MongoTemplate mtlogMongoTemplate;

    public List<MTLogInfo> QueryLogList(String dateStr, String keywords, int page, int rows) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        String tbName = "Nlog" + dateStr;
        Query query = new Query();
        if (keywords.isEmpty() == false) {
            Pattern pattern=Pattern.compile(".*?"+keywords+".*");
            query.addCriteria(Criteria.where("Message").regex(pattern));
        }
        query.skip((page-1)*rows);
        query.limit(rows);
        return mtlogMongoTemplate.find(query, MTLogInfo.class, tbName);
    }

    public long QueryLogCount(String dateStr, String keywords) {

        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        String tbName = "Nlog" + dateStr;
        Query query = new Query();
        if (keywords.isEmpty() == false) {
            Pattern pattern=Pattern.compile(".*?"+keywords+".*");
            query.addCriteria(Criteria.where("Message").regex(pattern));
        }
        return mtlogMongoTemplate.count(query, MTLogInfo.class, tbName);
    }*/
}
