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

import com.google.common.collect.Lists;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.act.utils.ActUtils;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Role;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.service.OfficeService;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workactivity.entity.Activity;
import com.jeeplus.modules.workactivity.service.ActivityService;
import com.jeeplus.modules.workfullmanage.entity.WorkFullManage;
import com.jeeplus.modules.workfullmanage.service.WorkFullManageService;
import com.jeeplus.modules.workfullsupervisorsheet.entity.WorkFullSupervisorsheet;
import com.jeeplus.modules.workfullsupervisorsheet.service.WorkFullSupervisorsheetService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 监理联系单Controller
 * @author fgy
 * @version 2017-11-08
 */
@SuppressWarnings("all")
@Controller
@RequestMapping(value = "${adminPath}/workfullsupervisorsheet/workFullSupervisorsheet")
public class WorkFullSupervisorsheetController extends BaseController {

	@Autowired
	private OfficeService officeService;
	@Autowired
	private ActTaskService actTaskService;
	@Autowired
	private WorkFullManageService workFullManageService;
	@Autowired
	private WorkFullSupervisorsheetService workFullSupervisorsheetService;
	@Autowired
	protected HistoryService historyService;
	@Autowired
	protected RepositoryService repositoryService;
	@Autowired
	protected RuntimeService runtimeService;
	@Autowired
	private ActivityService activityService;

	@ModelAttribute
	public WorkFullSupervisorsheet get(@RequestParam(required=false) String id) {
		WorkFullSupervisorsheet entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workFullSupervisorsheetService.get(id);
		}
		if (entity == null){
			entity = new WorkFullSupervisorsheet();
		}
		return entity;
	}

	/**
	 *  待添加监理联系单的项目列表
	 */
	@RequestMapping("workfullmanageList")
	public String workfullmanageList(WorkFullManage workFullManage, HttpServletRequest request, HttpServletResponse response, Model model){
		String userId = UserUtils.getUser().getId();
		//仅是普通员工
		if(!UserUtils.getSelectRoleInfo()){
			workFullManage.setQueryCon(userId);
		}

		Page<WorkFullManage> page = workFullSupervisorsheetService.findListOfWorkFullManage(new Page<WorkFullManage>(request, response), workFullManage);
		model.addAttribute("page", page);
		return "modules/workfullsupervisorsheet/workfullmanageList";
	}


	/**
	 * 监理联系单列表页面
	 */
	@RequiresPermissions("workfullsupervisorsheet:workFullSupervisorsheet:list")
	@RequestMapping(value = {"list", ""})
	public String list(WorkFullSupervisorsheet workFullSupervisorsheet, HttpServletRequest request, HttpServletResponse response, Model model) {
		String workFullManageId = request.getParameter("workFullManageId");

		if(StringUtils.isNotBlank(workFullManageId)){
			workFullSupervisorsheet.setWorkFullManageId(workFullManageId);
		}
		Page<WorkFullSupervisorsheet> page = workFullSupervisorsheetService.findPage(new Page<WorkFullSupervisorsheet>(request, response), workFullSupervisorsheet);
		model.addAttribute("page", page);
		model.addAttribute("workFullManage",workFullManageService.get(workFullManageId));
		model.addAttribute("workFullManageId",workFullManageId);
		return "modules/workfullsupervisorsheet/workFullSupervisorsheetList";
	}

	/**
	 * 查看，增加，编辑监理联系单表单页面
	 */
	@RequiresPermissions(value={"workfullsupervisorsheet:workFullSupervisorsheet:view","workfullsupervisorsheet:workFullSupervisorsheet:add","workfullsupervisorsheet:workFullSupervisorsheet:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(WorkFullSupervisorsheet workFullSupervisorsheet, Model model,HttpServletRequest request) {
		String dialog = request.getParameter("dialog");
		String workFullManageId = request.getParameter("workFullManageId");
		String listpage = request.getParameter("listpage");
		if(StringUtils.isBlank(workFullManageId)){
			workFullManageId = workFullSupervisorsheet.getWorkFullManageId();
		}
		if(StringUtils.isNotBlank(workFullManageId)){
			WorkFullManage workFullManage = workFullManageService.get(workFullManageId);
			model.addAttribute("workFullManage",workFullManage);
		}
		model.addAttribute("workFullSupervisorsheet", workFullSupervisorsheet);
		model.addAttribute("listpage",listpage);

		if(workFullSupervisorsheet.getAct()!=null && StringUtils.isNotBlank(workFullSupervisorsheet.getAct().getTaskId())){
			String taskId = workFullSupervisorsheet.getAct().getTaskId();
			return "modules/workfullsupervisorsheet/workFullSupervisorsheetAudit";
		}

		if("add".equals(dialog) || "edit".equals(dialog)){
			return "modules/workfullsupervisorsheet/workFullSupervisorsheetForm";
		}
		if("view".equals(dialog)){
			return "modules/workfullsupervisorsheet/workFullSupervisorsheetView";
		}

		return "modules/workfullsupervisorsheet/workFullSupervisorsheetForm";
	}

	/**
	 * 保存监理联系单
	 */
	@RequiresPermissions(value={"workfullsupervisorsheet:workFullSupervisorsheet:add","workfullsupervisorsheet:workFullSupervisorsheet:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(WorkFullSupervisorsheet workFullSupervisorsheet, Model model,HttpServletRequest request, HttpServletResponse response,
					   @RequestParam(value = "listpage",required = false)String listpage,RedirectAttributes redirectAttributes) throws Exception{
		//新添加（submit提交，toStore暂存），被驳回（reapply重新申请，repeal撤销）
		String submit = request.getParameter("submit");
		String workFullManageId = request.getParameter("workFullManageId");
		if (!beanValidator(model, workFullSupervisorsheet)){
			return form(workFullSupervisorsheet, model,request);
		}
		if(!workFullSupervisorsheet.getIsNewRecord()){//编辑表单保存
			WorkFullSupervisorsheet t = workFullSupervisorsheetService.get(workFullSupervisorsheet.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(workFullSupervisorsheet, t);//将编辑表单中的非NULL值覆盖数据库记录中的值

			//被驳回状态
			if (StringUtils.isNotBlank(t.getStatus()) &&t.getStatus().equals("3")){
				ProcessInstance processInstance = actTaskService.getProcIns(t.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);
					if("reapply".equals(submit)){act.setFlag("yes");}//重新申请
					if("repeal".equals(submit)){act.setFlag("no");}//撤销
					t.setAct(act);
				}
			}
			workFullSupervisorsheetService.save(t,workFullManageId,submit);//保存
			if("reapply".equals(submit)){
				addMessage(redirectAttributes,"重新申请监理联系单，并发往部门负责人审核");
			} else if("repeal".equals(submit)){
				addMessage(redirectAttributes,"已撤销监理联系单");
			}
			return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/?repage";
		}else{//新增表单保存
			workFullSupervisorsheet = workFullSupervisorsheetService.save(workFullSupervisorsheet,workFullManageId,submit);//保存
			if("submit".equals(submit)){
				String message = StringUtils.isNoneBlank(workFullSupervisorsheet.getId())?"保存监理联系单成功,并发往部门负责人审核":"监理联系单添加失败";
				addMessage(redirectAttributes,message);
			}else if("toStore".equals(submit)){
				String message = StringUtils.isNoneBlank(workFullSupervisorsheet.getId())?"已暂存该监理联系单":"监理联系单暂存失败";
				addMessage(redirectAttributes,message);
			}
			//主页面添加操作后刷新主页面，弹窗页面添加操作后刷新弹窗页面
			if(StringUtils.isNotBlank(listpage)&&listpage.equals("workfullmanageList")){
				return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/"+listpage;
			}
			return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/?repage";
		}
	}

	/**
	 * 删除监理联系单
	 */
	@RequiresPermissions("workfullsupervisorsheet:workFullSupervisorsheet:del")
	@RequestMapping(value = "delete")
	public String delete(WorkFullSupervisorsheet workFullSupervisorsheet, HttpServletRequest request, HttpServletResponse response, Model model) {
		workFullSupervisorsheetService.delete(workFullSupervisorsheet);
		WorkFullSupervisorsheet w = new WorkFullSupervisorsheet();
		w.setWorkFullManageId(workFullSupervisorsheet.getWorkFullManageId());
		model.addAttribute("workFullSupervisorsheet",w);
		model.addAttribute("message","删除监理联系单成功");
		return list(w,request,response,model);
	}
	/**
	 *  删除附件
	 */
	@RequestMapping("delFile")
	@ResponseBody
	public AjaxJson delFile(WorkFullSupervisorsheet workFullSupervisorsheet , HttpServletRequest request, Model model){
//		String attachmentFlag = request.getParameter("attachmentFlag");
//		workFullSupervisorsheetService.delFile(workFullSupervisorsheet,attachmentFlag);
//		workFullSupervisorsheet = workFullSupervisorsheetService.get(workFullSupervisorsheet.getId());
//		model.addAttribute("workFullSupervisorsheet",workFullSupervisorsheet);
//		return form(workFullSupervisorsheet,model,request);
		String workFullDesignchangeId = request.getParameter("id");
		String attaId = request.getParameter("attaId");
		String attachmentUrl = request.getParameter("attachmentUrl");
		workFullSupervisorsheet.setRemarks(attaId);
		workFullSupervisorsheetService.delFile(workFullSupervisorsheet,attachmentUrl);
		AjaxJson ajaxJson = new AjaxJson();
		ajaxJson.put("attachmentUrl",attachmentUrl);
		return ajaxJson;
	}
	/**
	 * 流程追踪
	 */
	@RequiresPermissions("workfullsupervisorsheet:workFullSupervisorsheet:view")
	@RequestMapping("getProcess")
	public String getProcess(WorkFullSupervisorsheet workFullSupervisorsheet, Model model){

		model.addAttribute("processInstanceId",workFullSupervisorsheet.getProcessInstanceId());
		return "modules/workfullsupervisorsheet/workFullSupervisorsheetTask";
	}
	/**
	 * 待办任务
	 */
	@RequestMapping("auditTodo")
	public String auditTodo(Act act , Model model , HttpServletRequest request, HttpServletResponse response){
		act.setProcDefKey("workFullSupervisorsheet");
		List<Act> actList = new ArrayList<>();
		actList.addAll(actTaskService.todoList(act));
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();

		List<Activity> activities = activityService.groupByActivityMenu("d957033a87ba431d9b92a586db449799",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			actList.addAll(actTaskService.todoList(act));
		}

		List<WorkFullSupervisorsheet>  supervisorsheetList = new ArrayList<>();
		Role role = UserUtils.getSelectRole().get(0);
		String officeId = "";
		if(role.getDataScope().equals("4")){
			User user = UserUtils.getUser();
			officeId = user.getOffice().getId();
		}

		for(Act a : actList){
		    //重新申请和撤销不在代办和历史任务列表展示
			if("audit".equals(a.getTask().getTaskDefinitionKey())||(! "reapply".equals(a.getTask().getTaskDefinitionKey()) && !a.getTask().getTaskDefinitionKey().contains("audit"))){
				WorkFullSupervisorsheet workFullSupervisorsheet = workFullSupervisorsheetService.getByProcessInstanceId(a.getProcInsId());
                if(workFullSupervisorsheet != null){
                    workFullSupervisorsheet = workFullSupervisorsheetService.get(workFullSupervisorsheet.getId());
                }
                if(workFullSupervisorsheet != null && workFullSupervisorsheet.getCompanyId().equals(companyId)){
                    User createBy = UserUtils.get(workFullSupervisorsheet.getCreateBy().getId());
                    if (StringUtils.isNotBlank(officeId)) {
                        if (officeId.equals(createBy.getOffice().getId())) {
                            if(a.getVars().getMap().get("applyUserId") != null){
                                User user = UserUtils.get(a.getVars().getMap().get("applyUserId").toString());
                                if(user != null){
                                    a.getVars().getMap().put("applyUserId",UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
                                }
                            }
                            workFullSupervisorsheet.setAct(a);
                            if(workFullSupervisorsheet.getWorkFullManage()!=null && workFullSupervisorsheet.getWorkFullManage().getId()!=null){
                                WorkFullManage workFullManage = workFullManageService.get(workFullSupervisorsheet.getWorkFullManage().getId());
                                workFullSupervisorsheet.setWorkFullManage(workFullManage);
                            }
                            if(StringUtils.isNotBlank(workFullSupervisorsheet.getId())){
                                workFullSupervisorsheet.setName(officeService.get(companyId).getName());
                            }
                            supervisorsheetList.add(workFullSupervisorsheet);
                        }
                    }else {
                        if(a.getVars().getMap().get("applyUserId") != null){
                            User user = UserUtils.get(a.getVars().getMap().get("applyUserId").toString());
                            if(user != null){
                                a.getVars().getMap().put("applyUserId",UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
                            }
                        }
                        workFullSupervisorsheet.setAct(a);
                        if(workFullSupervisorsheet.getWorkFullManage()!=null && workFullSupervisorsheet.getWorkFullManage().getId()!=null){
                            WorkFullManage workFullManage = workFullManageService.get(workFullSupervisorsheet.getWorkFullManage().getId());
                            workFullSupervisorsheet.setWorkFullManage(workFullManage);
                        }
                        if(StringUtils.isNotBlank(workFullSupervisorsheet.getId())){
                            workFullSupervisorsheet.setName(officeService.get(companyId).getName());
                        }
                        supervisorsheetList.add(workFullSupervisorsheet);
                    }
                }
            }
		}

		model.addAttribute("list", supervisorsheetList);
		return "modules/workfullsupervisorsheet/workFullSupervisorsheetAuditTodo";
	}
	/**
	 *  打开审核框
	 */
	@RequestMapping("applyOnWorkFullSupervisorsheet")
	public String applyOnWorkFullConstructsheet(Act act){
		// 获取流程XML上的表单KEY
		String formKey = "/workfullsupervisorsheet/workFullSupervisorsheet/form";
		//logger.info("------formKeys:"+formKeys);
		// 获取流程实例对象
		if (act.getProcInsId() != null){
			if(actTaskService.getProcIns(act.getProcInsId())!=null){
				act.setProcIns(actTaskService.getProcIns(act.getProcInsId()));
			}else{
				act.setFinishedProcIns(actTaskService.getFinishedProcIns(act.getProcInsId()));
			}
		}
		return "redirect:" + ActUtils.getFormUrl(formKey, act);
	}

	/**
	 * 部门负责人审核
	 */
	@RequestMapping("saveAudit")
	public String saveAudit(WorkFullSupervisorsheet workFullSupervisorsheet, Map<String, Object> vars, Model model, RedirectAttributes redirectAttributes) {
		/*if (StringUtils.isBlank(workFullSupervisorsheet.getAct().getComment())){
			addMessage(model, "请填写审核意见。");
			return form(workFullSupervisorsheet, model,null);
		}*/
		addMessage(redirectAttributes, "保存审核意见成功");
		workFullSupervisorsheetService.auditSave(workFullSupervisorsheet);
		return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/?repage";
	}
	/**
	 *  已办任务
	 */
	@RequestMapping("auditHistory")
	public String auditHistory(Act act , Model model,HttpServletRequest request,HttpServletResponse response){
		act.setProcDefKey("workFullSupervisorsheet");
		List<Act> list = actTaskService.historicList(act);
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();

		List<Activity> activities = activityService.groupByActivityMenu("d957033a87ba431d9b92a586db449799",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(actTaskService.historicList(act));
		}

		List<WorkFullSupervisorsheet> supervisorsheetList = new ArrayList<WorkFullSupervisorsheet>();
		Role role = UserUtils.getSelectRole().get(0);
		String officeId = "";
		if(role.getDataScope().equals("4")){
			User user = UserUtils.getUser();
			officeId = user.getOffice().getId();
		}

		for (Act a : list) {
		    //重新申请和撤销不展示在代办和历史任务列表里
            if(! "reapply".equals(a.getHistTask().getTaskDefinitionKey())){
                WorkFullSupervisorsheet workFullSupervisorsheet = workFullSupervisorsheetService.getByProcessInstanceId(a.getHistTask().getProcessInstanceId());
                if(workFullSupervisorsheet != null){
                    workFullSupervisorsheet = workFullSupervisorsheetService.get(workFullSupervisorsheet.getId());
                }
                if (workFullSupervisorsheet != null && workFullSupervisorsheet.getCompanyId().equals(companyId)) {
                    User createBy = UserUtils.get(workFullSupervisorsheet.getCreateBy().getId());
                    if (StringUtils.isNotBlank(officeId)) {
                        if (officeId.equals(createBy.getOffice().getId())) {
                            if (a.getVars().getMap().get("applyUserId")!=null){
                                a.getVars().getMap().put("applyUserId",UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
                            }
                            workFullSupervisorsheet.setAct(a);
                            if(workFullSupervisorsheet.getWorkFullManage()!=null && workFullSupervisorsheet.getWorkFullManage().getId()!=null){
                                WorkFullManage workFullManage = workFullManageService.get(workFullSupervisorsheet.getWorkFullManage().getId());
                                workFullSupervisorsheet.setWorkFullManage(workFullManage);
                            }
                            if (StringUtils.isNotBlank(workFullSupervisorsheet.getId())){
                                workFullSupervisorsheet.setName(officeService.get(companyId).getName());
                            }
                            supervisorsheetList.add(workFullSupervisorsheet);
                        }
                    }else {
                        if (a.getVars().getMap().get("applyUserId")!=null){
                            a.getVars().getMap().put("applyUserId",UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
                        }
                        workFullSupervisorsheet.setAct(a);
                        if(workFullSupervisorsheet.getWorkFullManage()!=null && workFullSupervisorsheet.getWorkFullManage().getId()!=null){
                            WorkFullManage workFullManage = workFullManageService.get(workFullSupervisorsheet.getWorkFullManage().getId());
                            workFullSupervisorsheet.setWorkFullManage(workFullManage);
                        }
                        if (StringUtils.isNotBlank(workFullSupervisorsheet.getId())){
                            workFullSupervisorsheet.setName(officeService.get(companyId).getName());
                        }
                        supervisorsheetList.add(workFullSupervisorsheet);
                    }
                }
            }
		}

		model.addAttribute("list", supervisorsheetList);
		return "modules/workfullsupervisorsheet/workFullSupervisorsheetAuditHistory";
	}

//	/**
//	 * 批量删除监理联系单(未实现)
//	 */
//	@RequiresPermissions("workfullsupervisorsheet:workFullSupervisorsheet:del")
//	@RequestMapping(value = "deleteAll")
//	public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
//		String idArray[] =ids.split(",");
//		for(String id : idArray){
//			workFullSupervisorsheetService.delete(workFullSupervisorsheetService.get(id));
//		}
//		addMessage(redirectAttributes, "删除监理联系单成功");
//		return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/?repage";
//	}
//
	/**
	 * 导出excel文件
	 */
	@RequiresPermissions("workfullsupervisorsheet:workFullSupervisorsheet:export")
    @RequestMapping(value = "export", method=RequestMethod.POST)
    public String exportFile(WorkFullSupervisorsheet workFullSupervisorsheet, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "监理联系单"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            Page<WorkFullSupervisorsheet> page = workFullSupervisorsheetService.findPage(new Page<WorkFullSupervisorsheet>(request, response, -1), workFullSupervisorsheet);
    		new ExportExcel("监理联系单", WorkFullSupervisorsheet.class).setDataList(page.getList()).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导出监理联系单记录失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/?repage";
    }

	/**
	 * 导入Excel数据

	 */
	@RequiresPermissions("workfullsupervisorsheet:workFullSupervisorsheet:import")
    @RequestMapping(value = "import", method=RequestMethod.POST)
    public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
		try {
			int successNum = 0;
			int failureNum = 0;
			StringBuilder failureMsg = new StringBuilder();
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<WorkFullSupervisorsheet> list = ei.getDataList(WorkFullSupervisorsheet.class);
			for (WorkFullSupervisorsheet workFullSupervisorsheet : list){
				try{
					workFullSupervisorsheetService.save(workFullSupervisorsheet);
					successNum++;
				}catch(ConstraintViolationException ex){
					failureNum++;
				}catch (Exception ex) {
					failureNum++;
				}
			}
			if (failureNum>0){
				failureMsg.insert(0, "，失败 "+failureNum+" 条监理联系单记录。");
			}
			addMessage(redirectAttributes, "已成功导入 "+successNum+" 条监理联系单记录"+failureMsg);
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入监理联系单失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/?repage";
    }

	/**
	 * 下载导入监理联系单数据模板
	 */
	@RequiresPermissions("workfullsupervisorsheet:workFullSupervisorsheet:import")
    @RequestMapping(value = "import/template")
    public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "监理联系单数据导入模板.xlsx";
    		List<WorkFullSupervisorsheet> list = Lists.newArrayList();
    		new ExportExcel("监理联系单数据", WorkFullSupervisorsheet.class, 1).setDataList(list).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入模板下载失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workfullsupervisorsheet/workFullSupervisorsheet/?repage";
    }




}