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

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.web.BaseController;
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.LeaveApply;
import com.jeeplus.modules.leaveapply.entity.LeaveDetail;
import com.jeeplus.modules.leaveapply.service.LeaveApplyService;
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.workstaff.dao.WorkStaffAchivesDao;
import com.jeeplus.modules.workstaff.entity.WorkStaffBasicInfo;
import com.jeeplus.modules.workstaff.service.WorkStaffBasicInfoService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
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.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 请假申请Controller
 * @author ssrh
 * @version 2018-09-10
 */
@Controller
@RequestMapping(value = "${adminPath}/leaveapply/leaveManage")
public class LeaveManageController 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;
	@Autowired
	private WorkStaffBasicInfoService workStaffBasicInfoService;


	
	/**
	 *
	 */
	@RequestMapping(value = {"list", ""})
	public String list(LeaveApply leaveApply, HttpServletRequest request, HttpServletResponse response, Model model) {
		leaveApply.setCompanyId(UserUtils.getSelectCompany().getId());
		Page<LeaveApply> page = leaveApplyService.getMangePage(new Page<LeaveApply>(request, response), leaveApply);
		model.addAttribute("page", page);
		return "modules/leaveapply/leaveMangeList";
	}


	@RequestMapping(value = "view")
	public String form(LeaveApply leaveApply, Model model) {
		String basicInfoId= request.getParameter("basicInfoId");
		workStaffBasicInfoService.getAchives(basicInfoId);
		String sumDays= request.getParameter("sumDays");
		leaveApply.setSumDays(sumDays);
		leaveApply.setBasicInfo(workStaffBasicInfoService.getAchives(basicInfoId));
			List<LeaveDetail> hisList=leaveDetailDao.findListHis(basicInfoId);
			leaveApply.setHisLeaveDetailList(hisList);
			model.addAttribute("leaveApply", leaveApply);
		return "modules/leaveapply/leaveMangeView";
	}
	@RequiresPermissions("leaveapply:leaveMange:reset")
	@RequestMapping(value = "reset")
	public String reset(LeaveApply leaveApply, RedirectAttributes redirectAttributes) {
		String basicInfoId= request.getParameter("basicInfoId");
		leaveApplyService.reset(basicInfoId);
		addMessage(redirectAttributes, "重置成功");
		return "redirect:"+Global.getAdminPath()+"/leaveapply/leaveManage/?repage";
	}
}