/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.workfullproprietorsheet.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.workfullproprietorsheet.entity.WorkFullProprietorsheet;
import com.jeeplus.modules.workfullproprietorsheet.service.WorkFullProprietorsheetService;
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-06
 */
@SuppressWarnings("all")
@Controller
@RequestMapping(value = "${adminPath}/workfullproprietorsheet/workFullProprietorsheet")
public class WorkFullProprietorsheetController extends BaseController {

	@Autowired
	private OfficeService officeService;
	@Autowired
	private ActTaskService actTaskService;
	@Autowired
	private WorkFullManageService workFullManageService;
	@Autowired
	private WorkFullProprietorsheetService workFullProprietorsheetService;
	@Autowired
	private ActivityService activityService;

	@ModelAttribute
	public WorkFullProprietorsheet get(@RequestParam(required=false) String id) {
		WorkFullProprietorsheet entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workFullProprietorsheetService.get(id);
		}
		if (entity == null){
			entity = new WorkFullProprietorsheet();
		}
		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 = workFullProprietorsheetService.findListOfWorkFullManage(new Page<WorkFullManage>(request, response), workFullManage);
		model.addAttribute("page", page);
		return "modules/workfullproprietorsheet/workfullmanageList";
	}


	/**
	 * 业主联系单列表页面
	 */
	@RequiresPermissions("workfullproprietorsheet:workFullProprietorsheet:list")
	@RequestMapping(value = {"list", ""})
	public String list(WorkFullProprietorsheet workFullProprietorsheet, HttpServletRequest request, HttpServletResponse response, Model model) {
		String workFullManageId = request.getParameter("workFullManageId");

		if(StringUtils.isNotBlank(workFullManageId)){
			workFullProprietorsheet.setWorkFullManageId(workFullManageId);
		}
		Page<WorkFullProprietorsheet> page = workFullProprietorsheetService.findPage(new Page<WorkFullProprietorsheet>(request, response), workFullProprietorsheet);
		model.addAttribute("page", page);
		model.addAttribute("workFullManage",workFullManageService.get(workFullManageId));
		model.addAttribute("workFullManageId",workFullManageId);
		return "modules/workfullproprietorsheet/workFullProprietorsheetList";
	}

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

		if(workFullProprietorsheet.getAct()!=null && StringUtils.isNotBlank(workFullProprietorsheet.getAct().getTaskId())){
			String taskId = workFullProprietorsheet.getAct().getTaskId();
			return "modules/workfullproprietorsheet/workFullProprietorsheetAudit";
		}

		if("add".equals(dialog) || "edit".equals(dialog)){
			return "modules/workfullproprietorsheet/workFullProprietorsheetForm";
		}
		if("view".equals(dialog)){
			return "modules/workfullproprietorsheet/workFullProprietorsheetView";
		}

		return "modules/workfullproprietorsheet/workFullProprietorsheetForm";
	}

	/**
	 * 保存业主联系单
	 */
	@RequiresPermissions(value={"workfullproprietorsheet:workFullProprietorsheet:add","workfullproprietorsheet:workFullProprietorsheet:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(WorkFullProprietorsheet workFullProprietorsheet, 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, workFullProprietorsheet)){
			return form(workFullProprietorsheet, model,request);
		}
		if(!workFullProprietorsheet.getIsNewRecord()){//编辑表单保存
			WorkFullProprietorsheet t = workFullProprietorsheetService.get(workFullProprietorsheet.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(workFullProprietorsheet, 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);
				}
			}
			workFullProprietorsheetService.save(t,workFullManageId,submit);//保存
			if("reapply".equals(submit)){
				addMessage(redirectAttributes,"重新申请业主联系单，并发往部门负责人审核");
			} else if("repeal".equals(submit)){
				addMessage(redirectAttributes,"已撤销业主联系单");
			}
			return "redirect:"+Global.getAdminPath()+"/workfullproprietorsheet/workFullProprietorsheet/?repage";
		}else{//新增表单保存
			workFullProprietorsheet = workFullProprietorsheetService.save(workFullProprietorsheet,workFullManageId,submit);//保存
			if("submit".equals(submit)){
				String message = StringUtils.isNoneBlank(workFullProprietorsheet.getId())?"保存业主联系单成功,并发往部门负责人审核":"监理联系单添加失败";
				addMessage(redirectAttributes,message);
			}else if("toStore".equals(submit)){
				String message = StringUtils.isNoneBlank(workFullProprietorsheet.getId())?"已暂存该业主联系单":"暂存业主联系单失败";
				addMessage(redirectAttributes,message);
			}
			//主页面添加操作后刷新主页面，弹窗页面添加操作后刷新弹窗页面
			if(StringUtils.isNotBlank(listpage)&&listpage.equals("workfullmanageList")){
				return "redirect:"+Global.getAdminPath()+"/workfullproprietorsheet/workFullProprietorsheet/"+listpage;
			}
			return "redirect:"+Global.getAdminPath()+"/workfullproprietorsheet/workFullProprietorsheet/?repage";
		}
	}
	/**
	 * 删除业主联系单
	 */
	@RequiresPermissions("workfullproprietorsheet:workFullProprietorsheet:del")
	@RequestMapping(value = "delete")
	public String delete(WorkFullProprietorsheet workFullProprietorsheet,HttpServletRequest request,HttpServletResponse response, Model model) {
		workFullProprietorsheetService.delete(workFullProprietorsheet);
		WorkFullProprietorsheet w = new WorkFullProprietorsheet();
		w.setWorkFullManageId(workFullProprietorsheet.getWorkFullManageId());
		model.addAttribute("workFullProprietorsheet",w);
		model.addAttribute("message","删除施工联系单成功");
		return list(w,request,response,model);
	}

	/**
	 *  删除附件
	 */
	@ResponseBody
	@RequestMapping("delFile")
	public AjaxJson delFile(WorkFullProprietorsheet workFullProprietorsheet , HttpServletRequest request, Model model){
//		String attachmentFlag = request.getParameter("attachmentFlag");
//		workFullProprietorsheetService.delFile(workFullProprietorsheet,attachmentFlag);
//		workFullProprietorsheet = workFullProprietorsheetService.get(workFullProprietorsheet.getId());
//		model.addAttribute("workFullProprietorsheet",workFullProprietorsheet);
//		return form(workFullProprietorsheet,model,request);
		String workFullDesignchangeId = request.getParameter("id");
		String attaId = request.getParameter("attaId");
		String attachmentUrl = request.getParameter("attachmentUrl");
		workFullProprietorsheet.setRemarks(attaId);
		workFullProprietorsheetService.delFile(workFullProprietorsheet,attachmentUrl);
		AjaxJson ajaxJson = new AjaxJson();
		ajaxJson.put("attachmentUrl",attachmentUrl);
		return ajaxJson;
	}
	/**
	 * 流程追踪
	 */
	@RequiresPermissions("workfullproprietorsheet:workFullProprietorsheet:view")
	@RequestMapping("getProcess")
	public String getProcess(WorkFullProprietorsheet workFullProprietorsheet, Model model){

		model.addAttribute("processInstanceId",workFullProprietorsheet.getProcessInstanceId());
		return "modules/workfullproprietorsheet/workFullProprietorsheetTask";
	}
	/**
	 * 待办任务
	 */
	@RequestMapping("auditTodo")
	public String auditTodo(Act act , Model model , HttpServletRequest request, HttpServletResponse response){
		act.setProcDefKey("workFullProprietorsheet");
		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("5ed1aca14c2a47aba1ccc22b08c831fc",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			actList.addAll(actTaskService.todoList(act));
		}

		List<WorkFullProprietorsheet>  proprietorsheetList = 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"))){
				WorkFullProprietorsheet workFullProprietorsheet = workFullProprietorsheetService.getByProcessInstanceId(a.getProcInsId());
				if(workFullProprietorsheet != null){
					workFullProprietorsheet = workFullProprietorsheetService.get(workFullProprietorsheet.getId());
				}
				if(workFullProprietorsheet != null && workFullProprietorsheet.getCompanyId().equals(companyId)){
					User createBy = UserUtils.get(workFullProprietorsheet.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());
								}
							}
							workFullProprietorsheet.setAct(a);
							if(workFullProprietorsheet.getWorkFullManage()!=null && workFullProprietorsheet.getWorkFullManage().getId()!=null){
								WorkFullManage workFullManage = workFullManageService.get(workFullProprietorsheet.getWorkFullManage().getId());
								workFullProprietorsheet.setWorkFullManage(workFullManage);
							}
							if(StringUtils.isNotBlank(workFullProprietorsheet.getId())){
								workFullProprietorsheet.setName(officeService.get(companyId).getName());
							}
							proprietorsheetList.add(workFullProprietorsheet);
						}
					}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());
							}
						}
						workFullProprietorsheet.setAct(a);
						if(workFullProprietorsheet.getWorkFullManage()!=null && workFullProprietorsheet.getWorkFullManage().getId()!=null){
							WorkFullManage workFullManage = workFullManageService.get(workFullProprietorsheet.getWorkFullManage().getId());
							workFullProprietorsheet.setWorkFullManage(workFullManage);
						}
						if(StringUtils.isNotBlank(workFullProprietorsheet.getId())){
							workFullProprietorsheet.setName(officeService.get(companyId).getName());
						}
						proprietorsheetList.add(workFullProprietorsheet);
					}
				}
			}
		}

		model.addAttribute("list", proprietorsheetList);
		return "modules/workfullproprietorsheet/workFullProprietorsheetAuditTodo";

	}
	/**
	 *  打开审核框
	 */
	@RequestMapping("applyOnWorkFullProprietorsheet")
	public String applyOnWorkFullConstructsheet(Act act){
		// 获取流程XML上的表单KEY
		String formKey = "/workfullproprietorsheet/workFullProprietorsheet/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(WorkFullProprietorsheet workFullProprietorsheet, Map<String, Object> vars, Model model, RedirectAttributes redirectAttributes) {
		/*if (StringUtils.isBlank(workFullProprietorsheet.getAct().getComment())){
			addMessage(model, "请填写审核意见。");
			return form(workFullProprietorsheet, model,null);
		}*/
		String message = workFullProprietorsheetService.auditSave(workFullProprietorsheet);
		addMessage(redirectAttributes, message);
		return "redirect:"+Global.getAdminPath()+"/workfullproprietorsheet/workFullProprietorsheet/?repage";
	}
	/**
	 *  已办任务
	 */
	@RequestMapping("auditHistory")
	public String auditHistory(Act act , Model model,HttpServletRequest request,HttpServletResponse response){
		act.setProcDefKey("workFullProprietorsheet");
		List<Act> list = actTaskService.historicList(act);
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();

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

		List<WorkFullProprietorsheet> proprietorsheetList = new ArrayList<WorkFullProprietorsheet>();
		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())){

				WorkFullProprietorsheet workFullProprietorsheet = workFullProprietorsheetService.getByProcessInstanceId(a.getHistTask().getProcessInstanceId());
				if(workFullProprietorsheet != null){
					workFullProprietorsheet = workFullProprietorsheetService.get(workFullProprietorsheet.getId());
				}
				if (workFullProprietorsheet != null && workFullProprietorsheet.getCompanyId().equals(companyId)) {
					User createBy = UserUtils.get(workFullProprietorsheet.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());
							}
							workFullProprietorsheet.setAct(a);
							if(workFullProprietorsheet.getWorkFullManage()!=null && workFullProprietorsheet.getWorkFullManage().getId()!=null){
								WorkFullManage workFullManage = workFullManageService.get(workFullProprietorsheet.getWorkFullManage().getId());
								workFullProprietorsheet.setWorkFullManage(workFullManage);
							}
							if (StringUtils.isNotBlank(workFullProprietorsheet.getId())){
								workFullProprietorsheet.setName(officeService.get(companyId).getName());
							}
							proprietorsheetList.add(workFullProprietorsheet);
						}
					}else {
						if (a.getVars().getMap().get("applyUserId")!=null){
							a.getVars().getMap().put("applyUserId",UserUtils.get(a.getVars().getMap().get("applyUserId").toString()).getName());
						}
						workFullProprietorsheet.setAct(a);
						if(workFullProprietorsheet.getWorkFullManage()!=null && workFullProprietorsheet.getWorkFullManage().getId()!=null){
							WorkFullManage workFullManage = workFullManageService.get(workFullProprietorsheet.getWorkFullManage().getId());
							workFullProprietorsheet.setWorkFullManage(workFullManage);
						}
						if (StringUtils.isNotBlank(workFullProprietorsheet.getId())){
							workFullProprietorsheet.setName(officeService.get(companyId).getName());
						}
						proprietorsheetList.add(workFullProprietorsheet);
					}
				}
			}
		}

		model.addAttribute("list", proprietorsheetList);
		return "modules/workfullproprietorsheet/workFullProprietorsheetAuditHistory";
	}

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

	/**
	 * 导入Excel数据

	 */
	@RequiresPermissions("workfullproprietorsheet:workFullProprietorsheet: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<WorkFullProprietorsheet> list = ei.getDataList(WorkFullProprietorsheet.class);
			for (WorkFullProprietorsheet workFullProprietorsheet : list){
				try{
					workFullProprietorsheetService.save(workFullProprietorsheet);
					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()+"/workfullproprietorsheet/workFullProprietorsheet/?repage";
    }
	
	/**
	 * 下载导入业主联系单数据模板
	 */
	@RequiresPermissions("workfullproprietorsheet:workFullProprietorsheet:import")
    @RequestMapping(value = "import/template")
    public String importFileTemplate(HttpServletRequest request,HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "业主联系单数据导入模板.xlsx";
    		List<WorkFullProprietorsheet> list = Lists.newArrayList();
			String agent = request.getHeader("USER-AGENT");
    		new ExportExcel("业主联系单数据", WorkFullProprietorsheet.class, 1).setDataList(list).write(response, fileName,agent).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入模板下载失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workfullproprietorsheet/workFullProprietorsheet/?repage";
    }
	
	
	

}