package com.xintong.visualinspection.controller;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xintong.visualinspection.bean.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xintong.visualinspection.service.CheckOtherService;
import com.xintong.visualinspection.service.StatisticsService;
import com.xintong.visualinspection.util.DateUtil;

/**
 * 文件名：StatisticsController
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
@RestController
@RequestMapping("/file")
public class FileExcelController extends BaseController {

	@Autowired
	private StatisticsService statisticsService;
	
	@Autowired
	private CheckOtherService checkOtherService  ;
	/**
     * 收费生产人员业务提升考核情况反馈表（所有员工排名）
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/business/feedback",method=RequestMethod.GET)
    public String getBusinessFeedback(HttpServletRequest req,HttpServletResponse resp,
    		@RequestParam Long dept_id,
    		@RequestParam Long parent_dept_id ,
    		@RequestParam Integer max_score ,
    		@RequestParam Integer min_score ,
    		@RequestParam Integer min_check_num ,
    		@RequestParam Integer max_check_num ,
    		@RequestParam Integer position_id ,
    		@RequestParam String start_date,@RequestParam String end_date,
    		@RequestParam String start_score,@RequestParam String end_score){
    	StatisticsBeanBO obj = new StatisticsBeanBO();
    
		Date start =  DateUtil.strParseDate(start_date);
		Date end =  DateUtil.strParseDate(end_date);
		obj.setDept_id(dept_id);
		obj.setParent_dept_id(parent_dept_id);
		obj.setStart_date(start);
		obj.setEnd_date(end);
		obj.setStart_score(start_score);
		obj.setEnd_score(end_score);
		obj.setMax_score(max_score);
		obj.setMin_score(min_score);
		obj.setMax_check_num(max_check_num);
		obj.setMin_check_num(min_check_num);
		obj.setPosition_id(position_id);
		
    	statisticsService.getBusinessFeedbackInfo(obj, req, resp);
    	return super.returnSuccessResult(null);
    }
    
    /**
     * 温馨服务考核情况反馈表（所有员工排名）
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/employee/order",method=RequestMethod.GET)
    public String getEmployeeOrder(HttpServletRequest req,HttpServletResponse resp,
    		@RequestParam Long dept_id,
    		@RequestParam Long parent_dept_id ,
    		@RequestParam Integer max_score ,
    		@RequestParam Integer min_score ,
    		@RequestParam Integer min_check_num ,
    		@RequestParam Integer max_check_num ,
    		@RequestParam Integer position_id ,
    		@RequestParam String start_date,@RequestParam String end_date,
    		@RequestParam String start_score,@RequestParam String end_score){
    	StatisticsBeanBO obj = new StatisticsBeanBO();
    
		Date start =  DateUtil.strParseDate(start_date);
		Date end =  DateUtil.strParseDate(end_date);
		obj.setDept_id(dept_id);
		obj.setParent_dept_id(parent_dept_id);
		obj.setStart_date(start);
		obj.setEnd_date(end);
		obj.setStart_score(start_score);
		obj.setEnd_score(end_score);
		obj.setMax_score(max_score);
		obj.setMin_score(min_score);
		obj.setMax_check_num(max_check_num);
		obj.setMin_check_num(min_check_num);
		obj.setPosition_id(position_id);
		
    	statisticsService.getEmployeeCheckedInfo(obj, req, resp);
    	return super.returnSuccessResult(null);
    }
    
    /**
     * 温馨服务检查千分考核扣分情况汇总表
     * @param obj
     * @return
     */
    @RequestMapping(value = "/score/info",method=RequestMethod.GET)
    public String getScoreInfo(HttpServletRequest req,HttpServletResponse resp,
    		@RequestParam String start_date,@RequestParam String end_date){
    	
    	StatisticsBean obj = new StatisticsBean();
    
		Date start =  DateUtil.strParseDate(start_date);
		Date end =  DateUtil.strParseDate(end_date);
		obj.setStart_date(start);
		obj.setEnd_date(end);
		
    	statisticsService.getFeeStationCheckedScore(obj, req, resp);
    	return super.returnSuccessResult(null);
    }
    
    /**
     * 温馨服务检查情况统计表
     */
    @RequestMapping(value = "/score/item/info",method=RequestMethod.GET)
    public String getScoreItemInfo(HttpServletRequest req,HttpServletResponse resp,
    		@RequestParam String start_date,@RequestParam String end_date){
    	StatisticsBean obj = new StatisticsBean();
		Date start = DateUtil.strParseDate(start_date);
		Date end = DateUtil.strParseDate(end_date);
		obj.setStart_date(start);
		obj.setEnd_date(end);
    	statisticsService.getFeeStationCheckItemScore(obj, req, resp);
    	return super.returnSuccessResult(null);
    }
    
    /**
     * 收费站申诉统计
     */
    @RequestMapping(value = "/appeal/info",method=RequestMethod.GET)
    public String getAppealStatisticExcel(HttpServletRequest req,HttpServletResponse resp,
    		@RequestParam String month,
    		@RequestParam(required=false) Integer centerId,
    		@RequestParam(required=false) Integer deptId){
    	CheckAppealStatistic obj = new CheckAppealStatistic();
    	if(deptId!=null){
    		obj.setDept_id(deptId);
    	}else if(centerId!=null){
    		obj.setParent_dept_id(centerId);
    	}
    	Calendar c = Calendar.getInstance();
    	Date time = DateUtil.strParseDate(month+"/25 23:00:00","yyyy/MM/dd HH:mm:ss");
    	c.setTime(time);
    	c.add(Calendar.MONTH,-1);
    	obj.setStart_time(c.getTime());
    	obj.setEnd_time(time);
    	statisticsService.getExcelAppealInfo(obj, month.replaceAll("/", "") , req, resp);
    	return super.returnSuccessResult(null);
    }
    
    /**
     * 稽查人员工作量统计
     */
    @RequestMapping(value = "/check/info",method=RequestMethod.GET)
    public String getCheckWorkExcel(HttpServletRequest req,HttpServletResponse resp,
    		@RequestParam String start_date,@RequestParam String end_date,
    		@RequestParam Integer queryType,@RequestParam(required=false) Integer user_id){
    	StatisticsBean obj = new StatisticsBean();
		Date start = DateUtil.strParseDate(start_date);
		Date end = DateUtil.strParseDate(end_date);
		obj.setStart_date(start);
		obj.setEnd_date(end);
		obj.setQueryType(queryType);
		if(user_id != null){
			obj.setUser_id(user_id+0L);			
		}
    	statisticsService.getCheckInfo(obj, req, resp);
    	return super.returnSuccessResult(null);
    }
    /**
     * @param req
     * @param resp
     * @param start_date
     * @param end_date
     * @return
     */
    @RequestMapping(value = "/operation/manage/integration",method=RequestMethod.GET)
    public String getOperationInfo(HttpServletRequest req,HttpServletResponse resp,
    		@RequestParam String start_date,@RequestParam String end_date){
    	StatisticsBean obj = new StatisticsBean();
		Date start = DateUtil.strParseDate(start_date);
		Date end = DateUtil.strParseDate(end_date);
		obj.setStart_date(start);
		obj.setEnd_date(end);
    	statisticsService.getOperationInfo(obj, req, resp);
    	return super.returnSuccessResult(null);
    }
    
    @RequestMapping(value = "/other/check/excel",method=RequestMethod.GET)
    public String getOtherCheck(HttpServletRequest req,HttpServletResponse resp,
    		 CheckOther checkOther){
    	checkOtherService.getOtherCheckExcel(checkOther, req, resp);
    	return super.returnSuccessResult(null);
    }

    @RequestMapping(value = "/other/check/static/excel",method=RequestMethod.GET)
    public String getOtherCheckststic(HttpServletRequest req,HttpServletResponse resp,
                                CheckOther checkOther){
        checkOtherService.getexcel(checkOther, req, resp);
        return super.returnSuccessResult(null);
    }

    @RequestMapping(value = "/dept/static/excel",method=RequestMethod.GET)
    public String getDeptCheckststic(HttpServletRequest req,HttpServletResponse resp,
                                      DeptStatistic deptStatistic){
        statisticsService.getDeptStatisticExcel(deptStatistic, req, resp);
        return super.returnSuccessResult(null);
    }
    
}
