package com.th.demo.service.impl.system;

import com.th.demo.mapping.system.SysLogClientMapper;
import com.th.demo.mapping.system.SysLogMapper;
import com.th.demo.model.system.SysLog;
import com.th.demo.model.system.SysLogClient;
import com.th.demo.service.system.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("SysLogService")
public class SysLogServiceImpl implements SysLogService {

	@Autowired
	public SysLogMapper sysLogMapper;
	
	
	@Autowired
	public SysLogClientMapper sysLogClientMapper;
	
	
	int num = 0;

	@Override
	public List<SysLog> query(String logStart, String logEnd, String logUserName, String logUserDesc, String logIp, String logHostName, String logJmId, String logType) {
		List<SysLog> list = new ArrayList<SysLog>();

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date dtParam2 = null;
		Date dtParam3 = null;
		if (logStart.equals("")) {
			dtParam2 = new Date();
		} else {
			try {
				dtParam2 = sdf.parse(logStart);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (logEnd.equals("")) {
			dtParam3 = new Date();
		} else {

			try {
				dtParam3 = sdf.parse(logEnd);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		list = sysLogMapper.selectByParam(dtParam2, dtParam3,    logUserName,  logUserDesc,  logIp,  logHostName,  logJmId,  logType);

		return list;
	}

	@Override
	public int add(SysLog sysLog) {
		num = 0;
		num = sysLogMapper.insert(sysLog);
		return num;

	}

	@Override
	public int addLogClient(SysLogClient sysLogClient) {
		num = 0;
		num = sysLogClientMapper.insert(sysLogClient);
		return num;
	}

}
