package com.saye.hrs.controller.system;

import java.util.Date;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.saye.hrs.commons.date.DateDUtil;
import com.saye.hrs.commons.log.ExceptionDUtil;
import com.saye.hrs.commons.log.LogUtil;
import com.saye.hrs.commons.page.PageUtil;
import com.saye.hrs.commons.page.TemplatePage;
import com.saye.hrs.model.Logger;
import com.saye.hrs.service.system.LoggerService;

@Controller
public class LoggerController {
	
	@Autowired
	private LoggerService loggerService;
	
	/**
	 * @description 到日志管理页面
	 * @author thuang       
	 * @created 2019年11月13日 下午5:27:29 
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/toLogger")
	public String toLogger(ModelMap modelMap){
		
		return "system/logger";
	}
	
	/**
	 * @description 查询所有日志数据
	 * @author thuang       
	 * @created 2019年11月13日 下午5:41:56 
	 * @return
	 */
	@RequestMapping("/findLogger")
	@ResponseBody
	public HashMap<String, Object> findLogger(String loggerType,String startTime,String endTime,Integer page,Integer limit ){
		HashMap<Object, Object> map=new HashMap<Object, Object>();
		map.put("loggerType", loggerType);
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		
		HashMap<String, Object> responseMap = new HashMap<String,Object>();
		try {
			PageHelper.startPage(page, limit);
			PageInfo<Logger> appsPageInfo = new PageInfo<Logger>(loggerService.findLogger(map));
			responseMap.put("code", 0);
			responseMap.put("msg", "");
			responseMap.put("count", appsPageInfo.getTotal());
			responseMap.put("data", appsPageInfo.getList());
		} catch (Exception e) {
			
			e.printStackTrace();
			LogUtil.error(this.getClass(), "查询所有日志数据失败，原因:"+ExceptionDUtil.getDetailExceptionMsg(e));
		
		}
		
		return responseMap;
	}
	
	/**
	 * @description 去his日志页面
	 * @author dqzhang       
	 * @created 2022年2月25日 上午9:26:19 
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/toHisLog")
	public String toHisLog(ModelMap modelMap){
		Date date = new Date();
		modelMap.addAttribute("startTime",DateDUtil.getPlusDays("yyyy-MM-dd", date, -7));
		modelMap.addAttribute("endTime",DateDUtil.DateToStr("yyyy-MM-dd", date));
		return "system/hisLog";
	}
	
	/**
	 * @description 查询所有his日志数据
	 * @author thuang       
	 * @created 2019年11月13日 下午5:41:56 
	 * @return
	 */
	@RequestMapping("/findHisLog")
	@ResponseBody
	public TemplatePage findHisLogList(String title,String startTime,String endTime,Integer page,Integer limit ){
		HashMap<Object, Object> map=new HashMap<Object, Object>();
		map.put("title", title);
		map.put("startTime", startTime);
		map.put("endTime", endTime);
		PageHelper.startPage(page, limit);
		PageInfo<HashMap<Object, Object>> appsPageInfo = new PageInfo<HashMap<Object, Object>>(loggerService.findHisLogList(map));
		return PageUtil.loadJsonPage(appsPageInfo);
	}
	
	
}
