package com.ssj.sys.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
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.ResponseBody;

import com.ssj.api.security.annotation.IgnoreSecurity;
import com.ssj.framework.basic.common.bean.SplitPage;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.framework.core.util.ResponseEntity;
import com.ssj.service.sys.analysis.service.AnalysisCountService;
import com.ssj.service.sys.analysis.service.AnalysisService;
import com.ssj.service.sys.analysis.service.AnalysisWeekService;
import com.ssj.sys.util.thirdparty.excel.CustomizeToExcel;
import com.ssj.sys.util.thirdparty.excel.ExcelColumn;

@RequestMapping("sys/analysis")
@Controller
public class AnalysisController extends BaseController {

	@Autowired
	private AnalysisService analysisService;
	
	@Autowired
	private AnalysisCountService analysisCountService;
	
	@Autowired
	private AnalysisWeekService analysisWeekService;
	
	@IgnoreSecurity
	@RequestMapping("/refresh/day")
	@ResponseBody
	public ResponseEntity refreshDay() {
		ResponseEntity responseEntity = new ResponseEntity();
		try{
        	logger.info("统计前一天的接口数据开始");
        	analysisCountService.runTaskAnalysisCount();
        	responseEntity.success("操作成功");
        }catch (Exception e) {
            logger.error("统计前一天的接口数据异常-->"+e.getMessage());
        }
		return responseEntity;
	}
	
	@IgnoreSecurity
	@RequestMapping("/refresh/week")
	@ResponseBody
	public ResponseEntity refreshWeek() {
		ResponseEntity responseEntity = new ResponseEntity();
		   try {
	            logger.info("统计前一天周的接口数据开始");
	            analysisWeekService.runTaskByAnalysisWeek();
	            responseEntity.success("操作成功");
	        } catch (Exception e) {
	            logger.error("统计前一天周的接口数据异常-->"+e.getMessage());
	        }
		return responseEntity;
	}

	
	//--------------------------数据汇总数据分析-------------------------------------

	@RequestMapping("/index")
	public String indexList(Model model) {
		return "sys/analysis/index";
	}

	@RequestMapping(value = "/index/data/count")
	@ResponseBody
	public ResponseEntity dataCount(String date) {
		ResponseEntity responseEntity = new ResponseEntity();
		Map<String, Object> map =new HashMap<String, Object>();
		try{
			if(StringUtils.isEmpty(date)) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
				date = sdf.format(new Date());
			}
			Long portNumCount=analysisService.countFxMerchantSumByPortNum();
			Long serviceCount=analysisService.countLibJoinConsumeSumByLibService(date);
			map.put("portNumCount", portNumCount);
			map.put("serviceCount", serviceCount);
			responseEntity.success(map,"操作成功");
		}catch (Exception e) {
			e.printStackTrace();
		}
		return responseEntity;
	}

	@RequestMapping(value = "/index/data/top")
	@ResponseBody
	public ResponseEntity dataTop(String date) {
		ResponseEntity responseEntity = new ResponseEntity();
		try{
			if(StringUtils.isEmpty(date)) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
				date = sdf.format(new Date());
			}
			List<Map<String, Object>> list= analysisService.countFxMerchantSumByTop(date);
			Map<String, Object> map =new HashMap<String, Object>();
			map.put("list", list);
			responseEntity.success(map,"操作成功");
		}catch (Exception e) {
			e.printStackTrace();
		}
		return responseEntity;
	}


	//--------------------------周数据汇总数据分析-------------------------------------

	@RequestMapping("/week")
	public String weekList(Model model,String weekDate) {
		if(StringUtils.isEmpty(weekDate)) {
			weekDate=getCurWeek();
		}
		model.addAttribute("weekDate", weekDate);
		return "sys/analysis/week";
	}


	@RequestMapping(value = "/week/data/count_1")
	@ResponseBody
	public ResponseEntity weekCount_1(String weekDate) {
		ResponseEntity responseEntity = new ResponseEntity();
		Map<String, Object> map =new HashMap<String, Object>();
		try{
			String[] weeks=getWeekDays(weekDate);
			String[] weekNexts=getNextWeekDays(weekDate);

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("date", weeks[0]);
			params.put("date2", weeks[1]);
			map.put("source_1", analysisWeekService.countLibJoinCountCommonByCountDate(params));

			params = new HashMap<String, Object>();
			params.put("date", weekNexts[0]);
			params.put("date2", weeks[1]);
			map.put("source_2",analysisWeekService.countVipActivateCountCommonByCountDate(params));

			responseEntity.success(map,"操作成功");
		}catch (Exception e) {
			e.printStackTrace();
		}
		return responseEntity;
	}


	@RequestMapping(value = "/week/data/count_1/export", method = RequestMethod.POST)
	@ResponseBody
	public void weekDataCount_1_Export(Model model,String weekDate) {
		ServletOutputStream os = null;
		try {
			String name="小塾学伴新增数据_"+weekDate;
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			List<Map<String,Object>> list= new ArrayList<Map<String,Object>>();
			Map<String,Object> map=new HashMap<String, Object>();

			String[] weeks=getWeekDays(weekDate);
			String[] weekNexts=getNextWeekDays(weekDate);

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("date", weeks[0]);
			params.put("date2", weeks[1]);
			map.put("column_0", analysisWeekService.countLibJoinCountCommonByCountDate(params).get("count_0"));

			params = new HashMap<String, Object>();
			params.put("date", weekNexts[0]);
			params.put("date2", weeks[1]);
			map.put("column_1",analysisWeekService.countVipActivateCountCommonByCountDate(params).get("count_0"));

			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("新签机构1周内账号开通数（校长&教师）", "column_0", 20));
			myColumns3.add(new ExcelColumn("新签机构2周内学生账号激活", "column_1", 20));
			list.add(map);
			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}



	@RequestMapping(value = "/week/data/count_2")
	@ResponseBody
	public ResponseEntity weekCount_2(String weekDate) {
		ResponseEntity responseEntity = new ResponseEntity();
		Map<String, Object> map =new HashMap<String, Object>();
		try{
			String[] weeks=getWeekDays(weekDate);
			String[] weekNexts=getNextWeekDays(weekDate);

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("date", getWeekByNum(weekDate));
			params.put("date2", getWeekByNum(weekDate)-1);
			map.put("source_1", analysisWeekService.countAnalysisWeekCountCommonByCountCurDate(params));


			params = new HashMap<String, Object>();
			params.put("date", getWeekByNum(weekDate));
			params.put("date2", getWeekByNum(weekDate)-4);
			params.put("count", 4);
			map.put("source_2",analysisWeekService.countAnalysisWeekCountCommonByCountMonthDate(params));


			params = new HashMap<String, Object>();
			params.put("date", getWeekByNum(weekDate));
			params.put("date2", getWeekByNum(weekDate)-12);
			params.put("count", 12);
			map.put("source_4",analysisWeekService.countAnalysisWeekCountCommonByCountMonthDate(params));

			params = new HashMap<String, Object>();
			params.put("date", weeks[0]);
			params.put("date2", weeks[1]);
			params.put("date3", weekNexts[0]);
			params.put("date4", weekNexts[1]);

			map.put("source_3", analysisCountService.countUploadWorkCommonByCountDate(params));
			map.put("source_5", analysisCountService.countRecallCommonByCountDate(params));
			responseEntity.success(map,"操作成功");
		}catch (Exception e) {
			e.printStackTrace();
		}
		return responseEntity;
	}


	@RequestMapping(value = "/week/data/count_2/export", method = RequestMethod.POST)
	@ResponseBody
	public void weekDataCount_2_Export(Model model,String weekDate) {
		ServletOutputStream os = null;
		try {
			String name="小塾学伴活泼用户数据_"+weekDate;
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			List<Map<String,Object>> list= new ArrayList<Map<String,Object>>();
			Map<String,Object> map=new HashMap<String, Object>();

			String[] weeks=getWeekDays(weekDate);
			String[] weekNexts=getNextWeekDays(weekDate);

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("date", getWeekByNum(weekDate));
			params.put("date2", getWeekByNum(weekDate)-1);
			map.put("column_0", analysisWeekService.countAnalysisWeekCountCommonByCountCurDate(params).get("count_0"));

			params = new HashMap<String, Object>();
			params.put("date", getWeekByNum(weekDate));
			params.put("date2", getWeekByNum(weekDate)-4);
			params.put("count", 4);
			map.put("column_1",analysisWeekService.countAnalysisWeekCountCommonByCountMonthDate(params).get("count_0"));


			params = new HashMap<String, Object>();
			params.put("date", getWeekByNum(weekDate));
			params.put("date2", getWeekByNum(weekDate)-12);
			params.put("count", 12);
			map.put("column_2",analysisWeekService.countAnalysisWeekCountCommonByCountMonthDate(params).get("count_0"));

			params = new HashMap<String, Object>();
			params.put("date", weeks[0]);
			params.put("date2", weeks[1]);
			params.put("date3", weekNexts[0]);
			params.put("date4", weekNexts[1]);

			map.put("column_3", analysisCountService.countUploadWorkCommonByCountDate(params).get("count_0"));
			map.put("column_4", analysisCountService.countRecallCommonByCountDate(params).get("count_0"));

			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("机构活泼数（账号活跃占比50%以上）", "column_0", 20));
			myColumns3.add(new ExcelColumn("新机构（1个月内）活泼数", "column_1", 20));
			myColumns3.add(new ExcelColumn("账号活跃数（周上传作业3天以上）", "column_2", 20));
			myColumns3.add(new ExcelColumn("老机构（持续用3个月）", "column_3", 20));
			myColumns3.add(new ExcelColumn("召回机构数据（1周不用机构）", "column_4", 20));
			list.add(map);
			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}




	@RequestMapping(value = "/week/data/count_3")
	@ResponseBody
	public ResponseEntity weekCount_3(String weekDate) {
		ResponseEntity responseEntity = new ResponseEntity();
		Map<String, Object> map =new HashMap<String, Object>();
		try{
			String[] weeks=getWeekDays(weekDate);
			String[] weekNexts=getNextWeekDays(weekDate);

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("date", weeks[0]);
			params.put("date2", weeks[1]);
			params.put("date3", weekNexts[0]);
			params.put("date4", weekNexts[1]);

			params.put("source", 1);
			params.put("types", "1;2;3;4");
			Map<String, Object> source_1 = analysisCountService.countAnalysisCountCommonByCountDate(params);


			params.put("source", 2);
			params.put("types", "12;13;15;16;17;18");
			Map<String, Object> source_2 = analysisCountService.countAnalysisCountCommonByCountDate(params);
			//19：计时 20作业登记 21周报 22 月报 23 学情（学期） 24 上传作业 25 查看批改结果
			params.put("source", 3);
			params.put("types", "5;6;7;8;9;10;11;19;20;21;22;23;24;25");
			Map<String, Object> source_3 = analysisCountService.countAnalysisCountCommonByCountDate(params);

			map.put("source_1", source_1);
			map.put("source_2", source_2);
			map.put("source_3", source_3);
			responseEntity.success(map,"操作成功");
		}catch (Exception e) {
			e.printStackTrace();
		}
		return responseEntity;
	}



	@RequestMapping(value = "/week/data/count_3/export", method = RequestMethod.POST)
	@ResponseBody
	public void weekDataCount_3_Export(Model model,String weekDate) {
		ServletOutputStream os = null;
		try {
			String name="小塾学伴功能使用数据_"+weekDate;
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			List<Map<String,Object>> list= new ArrayList<Map<String,Object>>();
			Map<String,Object> map=new HashMap<String, Object>();

			String[] weeks=getWeekDays(weekDate);
			String[] weekNexts=getNextWeekDays(weekDate);

			Map<String, Object> params = new HashMap<String, Object>();
			params.put("date", weeks[0]);
			params.put("date2", weeks[1]);
			params.put("date3", weekNexts[0]);
			params.put("date4", weekNexts[1]);

			params.put("source", 1);
			params.put("types", "1;2;3;4");
			Map<String, Object> source_1 = analysisCountService.countAnalysisCountCommonByCountDate(params);

			params.put("source", 2);
			params.put("types", "12;13;15;16;17;18");
			Map<String, Object> source_2 = analysisCountService.countAnalysisCountCommonByCountDate(params);

			params.put("source", 3);
			params.put("types", "5;6;7;8;9;10;11;19;20;21;22;23;24;25");
			Map<String, Object> source_3 = analysisCountService.countAnalysisCountCommonByCountDate(params);

			map.put("column_0", source_3.get("count_0"));
			map.put("column_1", source_3.get("count_1"));
			map.put("column_2", source_3.get("count_2"));
			map.put("column_3", source_3.get("count_3"));
			map.put("column_4", source_3.get("count_4"));
			map.put("column_5", source_3.get("count_5"));
			map.put("column_6", source_3.get("count_6"));
			map.put("column_19", source_3.get("count_7"));
			map.put("column_20", source_3.get("count_8"));
			map.put("column_21", source_3.get("count_9"));
			map.put("column_22", source_3.get("count_10"));
			map.put("column_23", source_3.get("count_11"));
			map.put("column_24", source_3.get("count_12"));
			map.put("column_25", source_3.get("count_13"));

			map.put("column_7", source_1.get("count_0"));
			map.put("column_8", source_1.get("count_1"));
			map.put("column_9", source_1.get("count_2"));
			map.put("column_10", source_1.get("count_3"));

			map.put("column_11", source_2.get("count_0"));
			map.put("column_12", source_2.get("count_1"));
			map.put("column_13", source_2.get("count_2"));
			map.put("column_14", source_2.get("count_3"));
			map.put("column_15", source_2.get("count_4"));
			map.put("column_16", source_2.get("count_5"));

			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("教师端-签到签离", "column_0", 20));
			myColumns3.add(new ExcelColumn("教师端-作业标注", "column_1", 20));
			myColumns3.add(new ExcelColumn("教师端-作业反馈编辑", "column_2", 20));
			myColumns3.add(new ExcelColumn("教师端-错题本", "column_3", 20));
			myColumns3.add(new ExcelColumn("教师端-定制练习", "column_4", 20));
			myColumns3.add(new ExcelColumn("教师端-学期回顾", "column_5", 20));
			myColumns3.add(new ExcelColumn("教师端-学习成长报告", "column_6", 20));
			//19：计时 20作业登记 21周报 22 月报 23 学情（学期） 24 上传作业 25 查看批改结果
			myColumns3.add(new ExcelColumn("教师端-计时", "column_19", 20));
			myColumns3.add(new ExcelColumn("教师端-作业登记", "column_20", 20));
			myColumns3.add(new ExcelColumn("教师端-成长报告·周报", "column_21", 20));
			myColumns3.add(new ExcelColumn("教师端-成长报告·月报", "column_22", 20));
			myColumns3.add(new ExcelColumn("教师端-成长报告·学期", "column_23", 20));
			myColumns3.add(new ExcelColumn("教师端-上传作业", "column_24", 20));
			myColumns3.add(new ExcelColumn("教师端-查看批改结果", "column_25", 20));

			myColumns3.add(new ExcelColumn("学生端-作业登记本", "column_7", 20));
			myColumns3.add(new ExcelColumn("学生端-计时", "column_8", 20));
			myColumns3.add(new ExcelColumn("学生端-上传作业", "column_9", 20));
			myColumns3.add(new ExcelColumn("学生端-查看批改结果", "column_10", 20));

			myColumns3.add(new ExcelColumn("家长端-作业任务", "column_11", 20));
			myColumns3.add(new ExcelColumn("家长端-错题本", "column_12", 20));
			myColumns3.add(new ExcelColumn("家长端-成长报告·周报", "column_13", 20));
			myColumns3.add(new ExcelColumn("家长端-成长报告·月报", "column_14", 20));
			myColumns3.add(new ExcelColumn("家长端-成长报告·学期", "column_15", 20));
			myColumns3.add(new ExcelColumn("家长端-定制练习", "column_16", 20));
			list.add(map);
			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}


	//--------------------------月机构数据汇总数据分析-------------------------------------
	@RequestMapping("/balance")
	public String balanceList(Model model,
							  @RequestParam(required = false, defaultValue = "10") int pageSize,
							  @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			data = sdf.format(new Date());
		}
		params.put("date", data);
		params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantServiceByDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/balance";
	}



	@RequestMapping(value = "/balance/export", method = RequestMethod.POST)
	@ResponseBody
	public void exportBalance(Model model) {
		ServletOutputStream os = null;
		try {
			String name="月机构会员分析";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
				data = sdf.format(new Date());
			}
			params.put("date", data);
			params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");

			Page<Map<String, Object>> page = analysisService.countFxMerchantServiceByDate(params, initPage(1, 10000));

			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("商户名称", "unit_name", 20));
			myColumns3.add(new ExcelColumn("机构名称", "league_name", 20));
			myColumns3.add(new ExcelColumn("新增人数", "count_1", 20));
			myColumns3.add(new ExcelColumn("流失人数", "count_2", 20));
			myColumns3.add(new ExcelColumn("有效人数", "count_3", 20));
			myColumns3.add(new ExcelColumn("结存人数", "count_4", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}



	@RequestMapping("/balance/vip")
	public String balanceVipList(Model model,
								 @RequestParam(required = false, defaultValue = "10") int pageSize,
								 @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			data = sdf.format(new Date());
		}
		params.put("date", data);
		params.put("id", request.getParameter("id"));
		params.put("name", request.getParameter("name"));
		params.put("type", request.getParameter("type"));

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantServiceByVipDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/balance_vip";
	}


	@RequestMapping(value = "/balance/vip/export", method = RequestMethod.POST)
	@ResponseBody
	public void balanceExportvip(Model model) {
		ServletOutputStream os = null;
		try {
			String name="月机构会员分析_会员明细表";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
				data = sdf.format(new Date());
			}
			params.put("date", data);
			params.put("id", request.getParameter("id"));
			params.put("name", request.getParameter("name"));
			params.put("type", request.getParameter("type"));

			Page<Map<String, Object>> page = analysisService.countFxMerchantServiceByVipDate(params, initPage(1, 1000));

			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("vipId", "vip_id", 20));
			myColumns3.add(new ExcelColumn("微信昵称", "wx_name", 20));
			myColumns3.add(new ExcelColumn("家长姓名", "parent_name", 20));
			myColumns3.add(new ExcelColumn("学生姓名", "child_name", 20));
			myColumns3.add(new ExcelColumn("开始服务时间", "start_time", 20));
			myColumns3.add(new ExcelColumn("结束服务时间", "end_time", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}


	//--------------------------学生端数据汇总数据分析-------------------------------------

	@RequestMapping("/student")
	public String studentList(Model model,
							  @RequestParam(required = false, defaultValue = "10") int pageSize,
							  @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		String data2=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			LocalDate day = LocalDate.now();
			data=day.plusDays(-1).toString();
		}
		if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
			data2=request.getParameter("date2");
		}else {
			LocalDate day = LocalDate.now();
			data2=day.plusDays(-1).toString();
		}

		params.put("date", data);
		params.put("date2", data2);
		params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");
		params.put("source", 1);
		params.put("types", "1;2;3;4");

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByCountDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/student";
	}


	@RequestMapping(value = "/student/export", method = RequestMethod.POST)
	@ResponseBody
	public void exportStudent(Model model) {
		ServletOutputStream os = null;
		try {
			String name="学生端数据分析";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			String data2=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				LocalDate day = LocalDate.now();
				data=day.plusDays(-1).toString();
			}
			if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
				data2=request.getParameter("date2");
			}else {
				LocalDate day = LocalDate.now();
				data2=day.plusDays(-1).toString();
			}

			params.put("date", data);
			params.put("date2", data2);
			params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");
			params.put("source", 1);
			params.put("types", "1;2;3;4");

			Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByCountDate(params, initPage(1, 10000));

			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("商户名称", "unit_name", 20));
			myColumns3.add(new ExcelColumn("机构名称", "league_name", 20));
			myColumns3.add(new ExcelColumn("作业登记本", "count_0", 20));
			myColumns3.add(new ExcelColumn("计时", "count_1", 20));
			myColumns3.add(new ExcelColumn("上传作业", "count_2", 20));
			myColumns3.add(new ExcelColumn("查看批改结果", "count_3", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}



	@RequestMapping("/student/info/{type}")
	public String student1List(Model model,@PathVariable String type,
							   @RequestParam(required = false, defaultValue = "10") int pageSize,
							   @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		String data2=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			LocalDate day = LocalDate.now();
			data=day.plusDays(-1).toString();
		}
		if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
			data2=request.getParameter("date2");
		}else {
			LocalDate day = LocalDate.now();
			data2=day.plusDays(-1).toString();
		}
		params.put("date", data);
		params.put("date2", data2);
		params.put("libId", request.getParameter("libId"));
		params.put("name", request.getParameter("name"));
		params.put("source", 1);
		params.put("type", type);

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByVipDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/student_info";
	}




	@RequestMapping(value = "/student/info/{type}/export", method = RequestMethod.POST)
	@ResponseBody
	public void studentInfoExport(Model model,@PathVariable String type,@RequestParam(required = false, defaultValue = "") String title ) {
		ServletOutputStream os = null;
		try {
			String name="学生端数据分析_"+title+"_会员明细表";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			String data2=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				LocalDate day = LocalDate.now();
				data=day.plusDays(-1).toString();
			}
			if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
				data2=request.getParameter("date2");
			}else {
				LocalDate day = LocalDate.now();
				data2=day.plusDays(-1).toString();
			}
			params.put("date", data);
			params.put("date2", data2);
			params.put("libId", request.getParameter("libId"));
			params.put("name", request.getParameter("name"));
			params.put("source", 1);
			params.put("type", type);

			Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByVipDate(params, initPage(1, 1000));

			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("vipId", "vip_id", 20));
			myColumns3.add(new ExcelColumn("微信昵称", "wx_name", 20));
			myColumns3.add(new ExcelColumn("家长姓名", "parent_name", 20));
			myColumns3.add(new ExcelColumn("学生姓名", "child_name", 20));
			myColumns3.add(new ExcelColumn("操作时间", "create_time", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}



	//--------------------------家长端数据汇总数据分析-------------------------------------
	@RequestMapping("/parent")
	public String parentList(Model model,
							 @RequestParam(required = false, defaultValue = "10") int pageSize,
							 @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		String data2=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			LocalDate day = LocalDate.now();
			data=day.plusDays(-1).toString();
		}
		if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
			data2=request.getParameter("date2");
		}else {
			LocalDate day = LocalDate.now();
			data2=day.plusDays(-1).toString();
		}
		params.put("date", data);
		params.put("date2", data2);
		params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");
		params.put("source", 2);
		params.put("types", "12;13;14;15;16;17;18");

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByCountDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/parent";
	}


	@RequestMapping(value = "/parent/export", method = RequestMethod.POST)
	@ResponseBody
	public void exportParent(Model model) {
		ServletOutputStream os = null;
		try {
			String name="家长端数据分析";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			String data2=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				LocalDate day = LocalDate.now();
				data=day.plusDays(-1).toString();
			}
			if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
				data2=request.getParameter("date2");
			}else {
				LocalDate day = LocalDate.now();
				data2=day.plusDays(-1).toString();
			}

			params.put("date", data);
			params.put("date2", data2);
			params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");
			params.put("source", 2);
			params.put("types", "12;13;14;15;16;17;18");

			Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByCountDate(params, initPage(1, 100000));

			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("商户名称", "unit_name", 20));
			myColumns3.add(new ExcelColumn("机构名称", "league_name", 20));
			myColumns3.add(new ExcelColumn("作业任务", "count_0", 20));
			myColumns3.add(new ExcelColumn("错题本", "count_1", 20));
			myColumns3.add(new ExcelColumn("成长报告", "count_2", 20));
			myColumns3.add(new ExcelColumn("成长报告·周报", "count_3", 20));
			myColumns3.add(new ExcelColumn("成长报告·月报", "count_4", 20));
			myColumns3.add(new ExcelColumn("成长报告·学期	", "count_5", 20));
			myColumns3.add(new ExcelColumn("定制练习", "count_6", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}


	@RequestMapping("/parent/info/{type}")
	public String parentInfoList(Model model,@PathVariable String type,
								 @RequestParam(required = false, defaultValue = "10") int pageSize,
								 @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		String data2=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			LocalDate day = LocalDate.now();
			data=day.plusDays(-1).toString();
		}
		if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
			data2=request.getParameter("date2");
		}else {
			LocalDate day = LocalDate.now();
			data2=day.plusDays(-1).toString();
		}
		params.put("date", data);
		params.put("date2", data2);
		params.put("libId", request.getParameter("libId"));
		params.put("name", request.getParameter("name"));
		params.put("source", 2);
		params.put("type", type);

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByVipDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/parent_info";
	}



	@RequestMapping(value = "/parent/info/{type}/export", method = RequestMethod.POST)
	@ResponseBody
	public void parentInfoExport(Model model,@PathVariable String type,@RequestParam(required = false, defaultValue = "") String title ) {
		ServletOutputStream os = null;
		try {
			String name="家长端数据分析_"+title+"_会员明细表";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			String data2=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				LocalDate day = LocalDate.now();
				data=day.plusDays(-1).toString();
			}
			if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
				data2=request.getParameter("date2");
			}else {
				LocalDate day = LocalDate.now();
				data2=day.plusDays(-1).toString();
			}
			params.put("date", data);
			params.put("date2", data2);
			params.put("libId", request.getParameter("libId"));
			params.put("name", request.getParameter("name"));
			params.put("source", 2);
			params.put("type", type);

			Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByVipDate(params, initPage(1, 1000));
			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("userId", "user_id", 20));
			myColumns3.add(new ExcelColumn("微信昵称", "wx_name", 20));
			myColumns3.add(new ExcelColumn("家长姓名", "parent_name", 20));
			myColumns3.add(new ExcelColumn("学生姓名", "child_name", 20));
			myColumns3.add(new ExcelColumn("操作时间", "create_time", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}


	//--------------------------教师端数据汇总数据分析-------------------------------------
	@RequestMapping("/teacher")
	public String teacherList(Model model,
							  @RequestParam(required = false, defaultValue = "10") int pageSize,
							  @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		String data2=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			LocalDate day = LocalDate.now();
			data=day.plusDays(-1).toString();
		}
		if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
			data2=request.getParameter("date2");
		}else {
			LocalDate day = LocalDate.now();
			data2=day.plusDays(-1).toString();
		}
		params.put("date", data);
		params.put("date2", data2);
		params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");
		params.put("source", 3);
		params.put("types", "5;6;7;8;9;10;11;19;20;21;22;23;24;25");

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByCountDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/teacher";
	}


	@RequestMapping(value = "/teacher/export", method = RequestMethod.POST)
	@ResponseBody
	public void exportTeacher(Model model) {
		ServletOutputStream os = null;
		try {
			String name="教师端数据分析";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			String data2=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				LocalDate day = LocalDate.now();
				data=day.plusDays(-1).toString();
			}
			if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
				data2=request.getParameter("date2");
			}else {
				LocalDate day = LocalDate.now();
				data2=day.plusDays(-1).toString();
			}

			params.put("date", data);
			params.put("date2", data2);
			params.put("unitName", StringUtils.isNotEmpty(request.getParameter("unitName"))?request.getParameter("unitName"):"");
			params.put("source", 3);
			params.put("types", "5;6;7;8;9;10;11;19;20;21;22;23;24;25");

			Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByCountDate(params, initPage(1, 100000));

			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("商户名称", "unit_name", 20));
			myColumns3.add(new ExcelColumn("机构名称", "league_name", 20));
			myColumns3.add(new ExcelColumn("签到签离", "count_0", 20));
			myColumns3.add(new ExcelColumn("作业标注", "count_1", 20));
			myColumns3.add(new ExcelColumn("作业反馈编辑", "count_2", 20));
			myColumns3.add(new ExcelColumn("错题本", "count_3", 20));
			myColumns3.add(new ExcelColumn("定制练习", "count_4", 20));
			myColumns3.add(new ExcelColumn("学期回顾", "count_5", 20));
			myColumns3.add(new ExcelColumn("学习成长报告", "count_6", 20));
			myColumns3.add(new ExcelColumn("计时", "count_7", 20));
			myColumns3.add(new ExcelColumn("作业登记", "count_8", 20));
			myColumns3.add(new ExcelColumn("成长报告·周报", "count_9", 20));
			myColumns3.add(new ExcelColumn("成长报告·月报", "count_10", 20));
			myColumns3.add(new ExcelColumn("成长报告·学期", "count_11", 20));
			myColumns3.add(new ExcelColumn("上传作业", "count_12", 20));
			myColumns3.add(new ExcelColumn("查看批改结果", "count_13", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}



	@RequestMapping("/teacher/info/{type}")
	public String teacherInfoList(Model model,@PathVariable String type,
								  @RequestParam(required = false, defaultValue = "10") int pageSize,
								  @RequestParam(required = false, defaultValue = "1") int pageNo) {

		Map<String, Object> params = new HashMap<String, Object>();
		String data=null;
		String data2=null;
		if(StringUtils.isNotEmpty(request.getParameter("date"))) {
			data=request.getParameter("date");
		}else {
			LocalDate day = LocalDate.now();
			data=day.plusDays(-1).toString();
		}
		if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
			data2=request.getParameter("date2");
		}else {
			LocalDate day = LocalDate.now();
			data2=day.plusDays(-1).toString();
		}
		params.put("date", data);
		params.put("date2", data2);
		params.put("libId", request.getParameter("libId"));
		params.put("name", request.getParameter("name"));
		params.put("source", 3);
		params.put("type", type);

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByUserDate(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		return "sys/analysis/teacher_info";
	}


	@RequestMapping(value = "/teacher/info/{type}/export", method = RequestMethod.POST)
	@ResponseBody
	public void teacherInfoExport(Model model,@PathVariable String type,@RequestParam(required = false, defaultValue = "") String title ) {
		ServletOutputStream os = null;
		try {
			String name="教师端数据分析_"+title+"_会员明细表";
			os = response.getOutputStream();response.reset();
			String fileName = new String(name.getBytes("gb2312"), "ISO8859-1") +".xlsx";
			response.setHeader("Content-disposition", "attachment; filename="+ fileName); //设定输出文件头
			response.setContentType("application/vnd.ms-excel;charset=UTF-8");
			response.setCharacterEncoding("utf-8");

			Map<String, Object> params = new HashMap<String, Object>();
			String data=null;
			String data2=null;
			if(StringUtils.isNotEmpty(request.getParameter("date"))) {
				data=request.getParameter("date");
			}else {
				LocalDate day = LocalDate.now();
				data=day.plusDays(-1).toString();
			}
			if(StringUtils.isNotEmpty(request.getParameter("date2"))) {
				data2=request.getParameter("date2");
			}else {
				LocalDate day = LocalDate.now();
				data2=day.plusDays(-1).toString();
			}
			params.put("date", data);
			params.put("date2", data2);
			params.put("libId", request.getParameter("libId"));
			params.put("name", request.getParameter("name"));
			params.put("source", 3);
			params.put("type", type);

			Page<Map<String, Object>> page = analysisService.countFxMerchantCommonByUserDate(params, initPage(1, 1000));
			List<Map<String,Object>> list= page.getContent();
			List<ExcelColumn> myColumns3 = new ArrayList<ExcelColumn>();
			myColumns3.add(new ExcelColumn("teacherId", "user_id", 20));
			myColumns3.add(new ExcelColumn("微信昵称", "wx_name", 20));
			myColumns3.add(new ExcelColumn("老师姓名", "user_name", 20));
			myColumns3.add(new ExcelColumn("操作时间", "create_time", 20));

			CustomizeToExcel.downFile(myColumns3, list, os);
		}catch (IOException e) {
			e.printStackTrace();
		}catch (Exception e1){
			e1.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.flush();
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	private static String[] getWeekDays(String week) {
		String[] days=new String[2];
		if(StringUtils.isEmpty(week)) {
			return days;
		}
		String[] weeks=week.replaceAll("周", "").replaceAll("年", "").replaceAll("第", "").trim().split("-");
		LocalDate day = LocalDate.now()
				.with(WeekFields.SUNDAY_START.weekBasedYear(), Integer.parseInt(weeks[0]))
				.with(WeekFields.SUNDAY_START.weekOfWeekBasedYear(), Integer.parseInt(weeks[1]))
				.with(WeekFields.SUNDAY_START.dayOfWeek(), 2);
		days[0]=day.toString();
		day=day.plusDays(6);
		days[1]=day.toString();
		return days;
	}


	private static String[] getNextWeekDays(String week) {
		String[] days=new String[2];
		if(StringUtils.isEmpty(week)) {
			return days;
		}
		String[] weeks=week.replaceAll("周", "").replaceAll("年", "").replaceAll("第", "").trim().split("-");
		LocalDate day = LocalDate.now()
				.with(WeekFields.SUNDAY_START.weekBasedYear(), Integer.parseInt(weeks[0]))
				.with(WeekFields.SUNDAY_START.weekOfWeekBasedYear(), Integer.parseInt(weeks[1]))
				.with(WeekFields.SUNDAY_START.dayOfWeek(), 2);
		day=day.plusDays(-1);
		days[1]=day.toString();
		day=day.plusDays(-6);
		days[0]=day.toString();
		return days;
	}

	private static Integer getWeekByNum(String week) {
		return Integer.parseInt(week.replaceAll("周", "").replaceAll("年", "").replaceAll("第", "").replaceAll("-", "").trim());
	}

	private static String getCurWeek() {
		LocalDate day = LocalDate.now();
		String week=day.getYear()+"年-第"+day.get(WeekFields.SUNDAY_START.weekOfWeekBasedYear())+"周";
		return week;
	}

	public static void main(String[] args) {

		String week="2020年-第29周";
		System.out.println(getWeekDays(week)[0]);
		System.out.println(getWeekDays(week)[1]);

		System.out.println(getNextWeekDays(week)[0]);
		System.out.println(getNextWeekDays(week)[1]);

		System.out.println( getCurWeek());


		LocalDate day = LocalDate.now();
		String data=day.plusDays(-1).toString();
		System.out.println(data);

	}
 	
	
}
