/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.leaveapply.web;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

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

import com.google.common.collect.Maps;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.leaveapply.dao.LeaveDetailDao;
import com.jeeplus.modules.leaveapply.entity.LeaveDetail;
import com.jeeplus.modules.leavetype.dao.LeaveTypeDao;
import com.jeeplus.modules.leavetype.entity.LeaveType;
import com.jeeplus.modules.leavetype.service.LeaveTypeService;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.DictUtils;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workborrowmangement.entity.WorkBorrowMangement;
import com.jeeplus.modules.workitemcollar.entity.WorkItemCollar;
import com.jeeplus.modules.workitemcollar.entity.WorkItemCollarCatalog;
import com.jeeplus.modules.workitemcollar.entity.WorkItemCollarItem;
import com.jeeplus.modules.workout.entity.WorkOut;
import com.jeeplus.modules.workstaff.dao.WorkStaffAchivesDao;
import com.jeeplus.modules.workstaff.entity.WorkStaffBasicInfo;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.leaveapply.entity.LeaveApply;
import com.jeeplus.modules.leaveapply.service.LeaveApplyService;

/**
 * 请假申请Controller
 * @author ssrh
 * @version 2018-09-10
 */
@Controller
@RequestMapping(value = "${adminPath}/leaveapply/leaveApply")
public class LeaveApplyController extends BaseController {
	@Autowired
	private HttpServletRequest request;
	@Autowired
	private LeaveApplyService leaveApplyService;
	@Autowired
	private WorkStaffAchivesDao workStaffAchivesDao;
	@Autowired
	private LeaveTypeService leaveTypeService;
	@Autowired
	private LeaveTypeDao leaveTypeDao;
	@Autowired
	private LeaveDetailDao leaveDetailDao;
	@Autowired
	private ActTaskService actTaskService;

	@ModelAttribute
	public LeaveApply get(@RequestParam(required=false) String id) {
		LeaveApply entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = leaveApplyService.get(id);
		}
		if (entity == null){
			entity = new LeaveApply();
		}
		return entity;
	}
	
	/**
	 * 请假申请列表页面
	 */
	@RequiresPermissions("leaveapply:leaveApply:list")
	@RequestMapping(value = {"list", ""})
	public String list(LeaveApply leaveApply, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<LeaveApply> page = leaveApplyService.findPage(new Page<LeaveApply>(request, response), leaveApply); 
		model.addAttribute("page", page);
		return "modules/leaveapply/leaveApplyList";
	}

	/**
	 * 查看，增加，编辑请假申请表单页面
	 */
	//@RequiresPermissions(value={"leaveapply:leaveApply:view","leaveapply:leaveApply:add","leaveapply:leaveApply:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(LeaveApply leaveApply, Model model) {
		String tabId= request.getParameter("tabId");
		if("1".equals(tabId)){//新增
			WorkStaffBasicInfo workStaffBasicInfo=leaveApplyService.getBasicInfo();
			leaveApply.setBasicInfo(workStaffBasicInfo);
			//查询历史明细
			List<LeaveDetail> hisList=leaveDetailDao.findListHis(workStaffBasicInfo.getId());
			leaveApply.setHisLeaveDetailList(hisList);
			model.addAttribute("leaveApply", leaveApply);
			return "modules/leaveapply/leaveApplyForm";
		}
		//查询请假明细
		LeaveDetail leaveDetail=new LeaveDetail();
		leaveDetail.setLeaveId(leaveApply.getId());
		List<LeaveDetail> list=leaveDetailDao.findList(leaveDetail);
		leaveApply.setLeaveDetailList(list);
		//查询历史明细
		List<LeaveDetail> hisList=leaveDetailDao.findListHis(leaveApply.getStaffId());
		leaveApply.setHisLeaveDetailList(hisList);
		model.addAttribute("leaveApply", leaveApply);
		if("2".equals(tabId)){//续假
			return "modules/leaveapply/leaveApplyExtendForm";
		}
		return "modules/leaveapply/leaveApplyForm";
	}
	@RequestMapping(value = "view")
	public String view(LeaveApply leaveApply, Model model) {
		String flat=request.getParameter("flat");
		//查询请假明细
		LeaveDetail leaveDetail=new LeaveDetail();
		leaveDetail.setLeaveId(leaveApply.getId());
		List<LeaveDetail> list=leaveDetailDao.findList(leaveDetail);
		leaveApply.setLeaveDetailList(list);
		//查询历史明细
		List<LeaveDetail> hisList=leaveDetailDao.findListHis(leaveApply.getStaffId());
		leaveApply.setHisLeaveDetailList(hisList);
		if("1".equals(flat)){
			leaveApply.setStatus("6");
		}
		leaveDetailDao.findMaxEndTime(leaveApply.getId());
		model.addAttribute("maxEndTime", leaveDetailDao.findMaxEndTime(leaveApply.getId()));
		model.addAttribute("leaveApply", leaveApply);
		return "modules/leaveapply/leaveApplyView";
	}
	//验证本次请假开始时间是否在上次请假时间后
	public static int compare_date(String DATE1, String DATE2) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date dt1 = df.parse(DATE1);
			Date dt2 = df.parse(DATE2);
			if (dt1.getTime() > dt2.getTime()) {
				return 1;
			} else if (dt1.getTime() < dt2.getTime()) {
				return -1;
			} else {
				return 0;
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return 0;
	}


	/**
	 * 保存请假申请,送审
	 */
	//@RequiresPermissions(value={"leaveapply:leaveApply:add","leaveapply:leaveApply:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(LeaveApply leaveApply, Model model, RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, leaveApply)){
			return form(leaveApply, model);
		}

		WorkStaffBasicInfo workStaffBasicInfo=leaveApplyService.getBasicInfo();
        leaveApply.setApplyer(UserUtils.getUser().getId());
        leaveApply.setOfficeId(UserUtils.getSelectOffice().getId());
        leaveApply.setCompanyId(UserUtils.getSelectCompany().getId());
        leaveApply.setBranchOffice(UserUtils.getSelectBranchOffice());
        //验证时间
		String validate=leaveApplyService.validate(leaveApply);
		if(!"".equals(validate)){
			if(leaveApply.getStatus()==null||"1".equals(leaveApply.getStatus())){
				leaveApply.setStatus("1");
				leaveApplyService.save(leaveApply);
			}
			addMessage(redirectAttributes, validate);
			return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
		}
		String validateSumDays=leaveApplyService.validateSumDays(leaveApply);
		if(!"".equals(validateSumDays)){
			if(leaveApply.getStatus()==null||"1".equals(leaveApply.getStatus())){
				leaveApply.setStatus("1");
				leaveApplyService.save(leaveApply);
			}
			addMessage(redirectAttributes, validateSumDays);
			return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
		}
		leaveApply.setStatus("2");
		if(!leaveApply.getIsNewRecord()){//编辑表单保存
			LeaveApply t = leaveApplyService.get(leaveApply.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(leaveApply, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			String str=leaveApplyService.saveBorrow(t);//保存
			if (StringUtils.isNotBlank(str)){
				addMessage(redirectAttributes, "请假申请提交失败:"+str);
			}else {
				addMessage(redirectAttributes, "请假申请已经提交");
			}
		}else{//新增表单保存
			String str=leaveApplyService.saveBorrow(leaveApply);//保存
			if (StringUtils.isNotBlank(str)){
				addMessage(redirectAttributes, "请假申请提交失败:"+str);
			}else {
				addMessage(redirectAttributes, "请假申请已经提交");
			}
		}
		addMessage(redirectAttributes, "保存请假申请成功");
		return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
	}
	//销假申请
	@RequestMapping(value = "backSave")
	public String backSave(LeaveApply leaveApply, Model model, RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, leaveApply)){
			return form(leaveApply, model);
		}
		leaveApply.setStatus("6");
		if(!leaveApply.getIsNewRecord()){//编辑表单保存
			LeaveApply t = leaveApplyService.get(leaveApply.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(leaveApply, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			String str=leaveApplyService.saveBack(t);//保存
			if (StringUtils.isNotBlank(str)){
				addMessage(redirectAttributes, "销假申请提交失败:"+str);
			}else {
				addMessage(redirectAttributes, "销假申请已经提交");
			}
		}else{//新增表单保存
			String str=leaveApplyService.saveBack(leaveApply);//保存
			if (StringUtils.isNotBlank(str)){
				addMessage(redirectAttributes, "销假申请提交失败:"+str);
			}else {
				addMessage(redirectAttributes, "销假申请已经提交");
			}
		}
		addMessage(redirectAttributes, "保存销假申请成功");
		return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
	}

	//续假申请
	@RequestMapping(value = "extendSave")
	public String extendSave(LeaveApply leaveApply, Model model, RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, leaveApply)){
			return form(leaveApply, model);
		}
		//验证时间
		String validate=leaveApplyService.validate(leaveApply);
		if(!"".equals(validate)){
			if(leaveApply.getStatus()==null||"5".equals(leaveApply.getStatus())){
				leaveApply.setStatus("5");
				leaveApplyService.saveExtend(leaveApply);
			}
			addMessage(redirectAttributes, validate);
			return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
		}
		leaveApply.setStatus("10");
		if(!leaveApply.getIsNewRecord()){//编辑表单保存
			LeaveApply t = leaveApplyService.get(leaveApply.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(leaveApply, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			String str=leaveApplyService.extendSave(t);//保存
			if (StringUtils.isNotBlank(str)){
				addMessage(redirectAttributes, "续假申请提交失败:"+str);
			}else {
				addMessage(redirectAttributes, "续假申请已经提交");
			}
		}else{//新增表单保存
			String str=leaveApplyService.extendSave(leaveApply);//保存
			if (StringUtils.isNotBlank(str)){
				addMessage(redirectAttributes, "续假申请提交失败:"+str);
			}else {
				addMessage(redirectAttributes, "续假申请已经提交");
			}
		}
		addMessage(redirectAttributes, "保存续假申请成功");
		return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
	}
	@RequestMapping(value = "store")
	public String store(LeaveApply leaveApply, Model model, RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, leaveApply)){
			return form(leaveApply, model);
		}

		//获取最后一次请假结束时间
		WorkStaffBasicInfo workStaffBasicInfo=leaveApplyService.getBasicInfo();
		leaveApply.setStatus("1");
		leaveApply.setApplyer(UserUtils.getUser().getId());
		leaveApply.setOfficeId(UserUtils.getSelectOffice().getId());
		leaveApply.setCompanyId(UserUtils.getSelectCompany().getId());
		leaveApply.setBranchOffice(UserUtils.getSelectBranchOffice());
		if(!leaveApply.getIsNewRecord()){//编辑表单保存
			LeaveApply t = leaveApplyService.get(leaveApply.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(leaveApply, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			leaveApplyService.save(t);//保存
		}else{//新增表单保存
			leaveApplyService.save(leaveApply);//保存
		}
		addMessage(redirectAttributes, "保存请假成功");
		return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
	}

	@RequestMapping(value = "modify")
	public String modify(LeaveApply leaveApply, Model model, RedirectAttributes redirectAttributes) {
		leaveApply=leaveApplyService.get(leaveApply.getId());
		ProcessInstance processInstance = actTaskService.getProcIns(leaveApply.getProcessInstanceId());
		if (processInstance!=null) {
			Task taskInfok = actTaskService.getCurrentTaskInfo(processInstance);
			Act act = new Act();
			act.setTaskId(taskInfok.getId());
			act.setTaskName(taskInfok.getName());
			act.setTaskDefKey(taskInfok.getTaskDefinitionKey());
			act.setProcDefId(taskInfok.getProcessDefinitionId());
			act.setProcInsId(taskInfok.getProcessInstanceId());
			act.setTask(taskInfok);
			leaveApply.setAct(act);
		}
		//查询请假明细
		LeaveDetail leaveDetail=new LeaveDetail();
		leaveDetail.setLeaveId(leaveApply.getId());
		List<LeaveDetail> list=leaveDetailDao.findList(leaveDetail);
		leaveApply.setLeaveDetailList(list);
		//查询历史明细
		List<LeaveDetail> hisList=leaveDetailDao.findListHis(leaveApply.getStaffId());
		leaveApply.setHisLeaveDetailList(hisList);
		model.addAttribute("leaveApply", leaveApply);
        if("9".equals(leaveApply.getStatus())){//销假
			return "modules/leaveapply/leaveApplyBackModifyApply";
		}else if("12".equals(leaveApply.getStatus())){//续假
			return "modules/leaveapply/leaveApplyExtendModifyApply";
		}
		return "modules/leaveapply/leaveApplyModifyApply";//请假
	}

	/**
	 * 工单执行（完成任务）
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "saveAudit")
	public String saveAudit(LeaveApply leaveApply, Model model,
							RedirectAttributes redirectAttributes) {
		try {
			List<User> users=new ArrayList<>();
			String flag = leaveApply.getAct().getFlag();
			String taskDefKey = leaveApply.getAct().getTaskDefKey();
			if("6".equals(leaveApply.getStatus())||"9".equals(leaveApply.getStatus())){
				users = UserUtils.getByProssType(leaveApply.getProcessInstanceId(),1);
			}else{
				if ("bmzr".equals(taskDefKey)){
					users = UserUtils.getByProssType(leaveApply.getProcessInstanceId(),2);
					if (users==null )
						users = UserUtils.getByRoleActivityEnname("fgld",2,leaveApply.getOfficeId(),"25",leaveApply.getCreateBy());
				}else  if ("fgld".equals(taskDefKey)){
					users = UserUtils.getByProssType(leaveApply.getProcessInstanceId(),3);
					if (users==null )
						users = UserUtils.getByRoleActivityEnname("zjl", 3, leaveApply.getOfficeId(), "25", leaveApply.getCreateBy());
				}else if ("zjl".equals(taskDefKey)){
					users = UserUtils.getByProssType(leaveApply.getProcessInstanceId(),3);
				}else if ("modifyApply".equals(taskDefKey)){
					users = UserUtils.getByProssType(leaveApply.getProcessInstanceId(),1);
					if(users==null){
						users = UserUtils.getByRoleActivityEnname("bmzr", 2, UserUtils.getSelectOffice().getId(), "25", leaveApply.getCreateBy());
					}
				}
			}
			if ("yes".equals(flag) && (users==null || users.size()==0)){
				addMessage(redirectAttributes, "审批失败,审批人为空,请联系管理员！");
			}else {
				if("2".equals(leaveApply.getStatus())||"4".equals(leaveApply.getStatus())){//请假
					String str = leaveApplyService.auditSave(leaveApply,users);
					addMessage(redirectAttributes, str);
				}else if("6".equals(leaveApply.getStatus())||"9".equals(leaveApply.getStatus())){//销假
					String str = leaveApplyService.auditBackSave(leaveApply,users);
					addMessage(redirectAttributes, str);
				}else if("10".equals(leaveApply.getStatus())||"12".equals(leaveApply.getStatus())){//续假
					String str = leaveApplyService.auditExtendSave(leaveApply,users);
					addMessage(redirectAttributes, str);
				}
			}
		}catch (Exception e){
			addMessage(redirectAttributes, "审批失败");
		}

		if (StringUtils.isNotBlank(leaveApply.getHome()) && "home".equals(leaveApply.getHome())){
			return "redirect:" + Global.getAdminPath() + "/home/?repage";
		}else {
			return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
		}
	}


	@RequestMapping(value = "getProcess")
	public String getProcess(LeaveApply leaveApply, Model model, HttpServletRequest request){
		model.addAttribute("processInstanceId", leaveApply.getProcessInstanceId());
		return "modules/leaveapply/leaveApplyTask";
	}

	@RequestMapping(value = "revoke")
	public String revoke(HttpServletRequest request, RedirectAttributes redirectAttributes) {
		HashMap<String, String> requestMap = findRequestMap(request);
		String processInstanceId = requestMap.get("processInstanceId");
		String id = requestMap.get("id");
		try {
			leaveApplyService.cancelProcess(id);
			addMessage(redirectAttributes, "撤回请假申请成功");
		}catch (Exception e){
			logger.info(e.getMessage());
			addMessage(redirectAttributes, "撤回请假申请失败");
		}
		return "redirect:" + Global.getAdminPath() + "/leaveapply/leaveApply/?repage";
	}
	@RequestMapping(value = "revokeBack")
	public String revokeBack(HttpServletRequest request, RedirectAttributes redirectAttributes) {
		HashMap<String, String> requestMap = findRequestMap(request);
		String processInstanceId = requestMap.get("processInstanceId");
		String id = requestMap.get("id");
		try {
			leaveApplyService.cancelProcessBack(id);
			addMessage(redirectAttributes, "撤回销假申请成功");
		}catch (Exception e){
			logger.info(e.getMessage());
			addMessage(redirectAttributes, "撤回销假申请失败");
		}
		return "redirect:" + Global.getAdminPath() + "/leaveapply/leaveApply/?repage";
	}
	@RequestMapping(value = "revokeExtend")
	public String revokeExtend(HttpServletRequest request, RedirectAttributes redirectAttributes) {
		HashMap<String, String> requestMap = findRequestMap(request);
		String processInstanceId = requestMap.get("processInstanceId");
		String id = requestMap.get("id");
		try {
			leaveApplyService.cancelProcessExtend(id);
			addMessage(redirectAttributes, "撤回请假申请成功");
		}catch (Exception e){
			logger.info(e.getMessage());
			addMessage(redirectAttributes, "撤回请假申请失败");
		}
		return "redirect:" + Global.getAdminPath() + "/leaveapply/leaveApply/?repage";
	}
	/**
	 * 删除请假申请
	 */
	//@RequiresPermissions("leaveapply:leaveApply:del")
	@RequestMapping(value = "delete")
	public String delete(LeaveApply leaveApply, RedirectAttributes redirectAttributes) {
		leaveApplyService.delete(leaveApply);
		addMessage(redirectAttributes, "删除请假申请成功");
		return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveApply/?repage";
	}

	/**
	 * 获取机构JSON数据。
	 *
	 * @param extId    排除的ID
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "treeDataTypeInfo")
	public List<Map<String, Object>> treeData(@RequestParam(required = false) String extId,
											  @RequestParam(required = false) Boolean isAll,
											  @RequestParam(required = false) String typeId,
											  HttpServletResponse response) {
		List<Map<String, Object>> mapList = Lists.newArrayList();
		LeaveType leaveType=new LeaveType();
		leaveType.setCompanyId(UserUtils.getSelectCompany().getId());
		leaveType.setState("0");
		List<LeaveType> list = leaveTypeService.findList(leaveType);
		List<LeaveType> newList=new ArrayList<>();
		newList.addAll(list);
		for(LeaveType leaveType1:list){
			if("4".equals(leaveType1.getMethod())){//一次性
				List<LeaveDetail> list1=leaveDetailDao.onlyOne(leaveType1.getId(),leaveApplyService.getBasicInfo().getId());
				if(list1!=null&&list1.size()>0){
					newList.remove(leaveType1);
				}
			}else if("3".equals(leaveType1.getMethod())&&!"1".equals(leaveType1.getMaxDays())){//单次
				String sumDays=leaveDetailDao.maxdays(leaveType1.getId(),leaveApplyService.getBasicInfo().getId());
				if(Double.parseDouble(sumDays)>=Double.parseDouble(leaveType1.getSetDays())){
					newList.remove(leaveType1);
				}
			}
		}
		for (int i = 0; i < newList.size(); i++) {
			LeaveType e = newList.get(i);
			if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))) {
				Map<String, Object> map = Maps.newHashMap();
				map.put("id", e.getId());
				map.put("pIds", e.getParentIds());
				map.put("pId", e.getParentId());
				map.put("name", e.getName());
				if (e.getIsEnd() != null && "0".equals(e.getIsEnd())) {
					map.put("isParent", true);
				}
				mapList.add(map);
			}
		}
		return mapList;
	}
	//获取入职信息
	@RequestMapping(value = "typeInfo")
	@ResponseBody
	public LeaveType typeInfo()  {
		String ids=request.getParameter("ids");
		LeaveType leaveType=leaveTypeDao.get(ids);
		leaveType.setModel(DictUtils.getDictLabel(leaveType.getModel(),"fake_model",""));
		return  leaveType;
	}
	//获取入职信息
	@RequestMapping(value = "addApply")
	@ResponseBody
	public int addApply()  {
		int count=0;
		WorkStaffBasicInfo workStaffBasicInfo=leaveApplyService.getBasicInfo();
		if(workStaffBasicInfo==null){
			return  -1;
		}
		List<LeaveApply> list=leaveApplyService.getCount();
		if(list!=null&&list.size()>0){
			count=1;
		}
		return  count;
	}
	//获取入职信息
	@RequestMapping(value = "weekDays")
	@ResponseBody
	public int weekDays(){
		String startDate=request.getParameter("startDate");
		String endDate=request.getParameter("endDate");
		int count=leaveApplyService.startMonthTask(startDate,endDate);
		return  count;
	}
}