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

import com.google.common.collect.Lists;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.oss.OSSClientUtil;
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.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.projectrecord.entity.ProjectRecords;
import com.jeeplus.modules.projectrecord.enums.ProjectStatusEnum;
import com.jeeplus.modules.projectrecord.service.ProjectRecordsService;
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.utils.DictUtils;
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.workclientinfo.entity.WorkClientInfo;
import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
import com.jeeplus.modules.workcontractinfo.service.WorkContractInfoService;
import com.jeeplus.modules.workprojectnotify.entity.WorkProjectNotify;
import com.jeeplus.modules.workprojectnotify.service.WorkProjectNotifyService;
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 java.io.*;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.*;

/**
 * 项目登记Controller
 * @author ppt
 * @version 2018-05-02
 */
@Controller
@RequestMapping(value = "${adminPath}/project/projectRecords")
public class ProjectRecordsController extends BaseController {

	@Autowired
	private ProjectRecordsService projectRecordsService;

	@Autowired
	private WorkContractInfoService contractInfoService;
	@Autowired
	private ActTaskService actTaskService;
	@Autowired
	private ActivityService activityService;

	private static String template_path = Global.getProjectTemplatePath()+"咨询工作方案.xlsx";
	private static String template_name = "咨询工作方案.xlsx";

	@ModelAttribute
	public ProjectRecords get(@RequestParam(required=false) String id) {
		ProjectRecords entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = projectRecordsService.get(id);
		}
		if (entity == null){
			entity = new ProjectRecords();
		}
		return entity;
	}
	
	/**
	 * 项目列表页面
	 */
	@RequiresPermissions("project:projectRecords:list")
	@RequestMapping(value = {"list", ""})
	public String list(ProjectRecords projectRecords, HttpServletRequest request, HttpServletResponse response, Model model) {
        if(UserUtils.isManager()){
            model.addAttribute("flag","1");
        }
		Page<ProjectRecords> page = projectRecordsService.findPage(new Page<ProjectRecords>(request, response), projectRecords); 
		model.addAttribute("page", page);
		return "modules/projectrecord/projectRecordsList";
	}

	/**
	 * 查看，增加，编辑项目表单页面
	 */
	@RequiresPermissions(value={"project:projectRecords:add","project:projectRecords:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(ProjectRecords projectRecords, Model model) {
		if (projectRecords!=null&&StringUtils.isNotBlank(projectRecords.getId())) {
			projectRecords = projectRecordsService.get(projectRecords.getId());
            projectRecordsService.queryProjectDetail(projectRecords);
		}else {
		    projectRecords.setCreateBy(UserUtils.getUser());
		    projectRecords.setCreateDate(new Date());
        }
		model.addAttribute("projectRecords", projectRecords);
		return "modules/projectrecord/projectRecordsForm";
	}

	/**
	 * 查看
	 * @param projectRecords
	 * @param model
	 * @return
	 */
	@RequiresPermissions(value={"project:projectRecords:view"})
	@RequestMapping(value = "view")
	public String view(ProjectRecords projectRecords, Model model) {
		if (projectRecords!=null&&StringUtils.isNotBlank(projectRecords.getId())) {
			projectRecordsService.queryProjectDetail(projectRecords);
		}
		model.addAttribute("projectRecords", projectRecords);
		return "modules/projectrecord/projectRecordsView";
	}

	/**
	 * 保存项目
	 */
	@RequiresPermissions(value={"project:projectRecords:add","project:projectRecords:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(ProjectRecords projectRecords, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, projectRecords)){
			return form(projectRecords, model);
		}
		try {
//            projectRecords.setProjectStatus(ProjectStatusEnum.IN_APRL.getValue());
            if (!projectRecords.getIsNewRecord()) {//编辑表单保存
                ProjectRecords t = projectRecordsService.get(projectRecords.getId());//从数据库取出记录的值
                MyBeanUtils.copyBeanNotNull2Bean(projectRecords, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
                projectRecordsService.saveProject(t,ProjectStatusEnum.IN_APRL);//保存
            } else {//新增表单保存
                projectRecordsService.saveProject(projectRecords,ProjectStatusEnum.IN_APRL);//保存
            }
            addMessage(redirectAttributes, "保存项目成功");
        }catch (Exception e){
		    logger.error("保存项目异常：",e);
            addMessage(redirectAttributes, "保存项目异常:"+e.getMessage());
        }
		return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
	}
	/**
	 * 保存项目
	 */
	@RequiresPermissions(value={"project:projectRecords:add","project:projectRecords:edit"},logical=Logical.OR)
	@RequestMapping(value = "tstore")
	public String tStore(ProjectRecords projectRecords, Model model, RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, projectRecords)){
			return form(projectRecords, model);
		}
		try {
//            projectRecords.setProjectStatus(ProjectStatusEnum.TSTORE.getValue());
            if (!projectRecords.getIsNewRecord()) {//编辑表单保存
                ProjectRecords t = projectRecordsService.get(projectRecords.getId());//从数据库取出记录的值
                MyBeanUtils.copyBeanNotNull2Bean(projectRecords, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
                projectRecordsService.saveProject(t,ProjectStatusEnum.TSTORE);//保存
            } else {//新增表单保存
                projectRecordsService.saveProject(projectRecords,ProjectStatusEnum.TSTORE);//保存
            }
            addMessage(redirectAttributes, "暂存项目成功");
        }catch (Exception e){
            logger.error("暂存项目异常：",e);
            addMessage(redirectAttributes, "暂存项目异常:"+e.getMessage());
        }
		return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
	}

    /**
     * 编辑项目表单页面
     */
    @RequiresPermissions(value={"project:projectRecords:edit"},logical=Logical.OR)
    @RequestMapping(value = "modify")
    public String modify(ProjectRecords projectRecords, Model model,RedirectAttributes redirectAttributes) {
        projectRecords=projectRecordsService.get(projectRecords.getId());
        ProcessInstance processInstance = actTaskService.getProcIns(projectRecords.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);
            projectRecords.setAct(act);
        }

        projectRecordsService.queryProjectDetail(projectRecords);
        model.addAttribute("projectRecords", projectRecords);
        return "modules/projectrecord/projectRecordsModify";
    }

	/**
	 * 删除项目
	 */
	@RequiresPermissions("project:projectRecords:del")
	@RequestMapping(value = "delete")
	public String delete(ProjectRecords projectRecords, RedirectAttributes redirectAttributes) {
		int status = projectRecords.getProjectStatus();
		if(status==ProjectStatusEnum.TSTORE.getValue()||status==ProjectStatusEnum.REJECTED.getValue()||status==ProjectStatusEnum.RECALL.getValue()){
			projectRecordsService.delete(projectRecords);
			addMessage(redirectAttributes, "删除项目成功");
			return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
		}else {
			addMessage(redirectAttributes, "删除项目失败，只有“暂存”、“驳回”、“撤回”状态的项目才能删除");
		}
		return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
	}
	
	/**
	 * 批量删除项目
	 */
	@RequiresPermissions("project:projectRecords:del")
	@RequestMapping(value = "deleteAll")
	public String deleteAll(String ids, RedirectAttributes redirectAttributes) {
		String idArray[] =ids.split(",");
		for(String id : idArray){
			projectRecordsService.delete(projectRecordsService.get(id));
		}
		addMessage(redirectAttributes, "删除项目成功");
		return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
	}
	
	/**
	 * 导出excel文件
	 */
	@RequiresPermissions("project:projectRecords:export")
    @RequestMapping(value = "export", method=RequestMethod.POST)
    public String exportFile(ProjectRecords projectRecords, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "项目"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            Page<ProjectRecords> page = projectRecordsService.findPage(new Page<ProjectRecords>(request, response, -1), projectRecords);
    		new ExportExcel("项目", ProjectRecords.class).setDataList(page.getList()).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导出项目记录失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
    }

	/**
	 * 下载导入项目数据模板
	 */
	@RequiresPermissions("project:projectRecords:import")
    @RequestMapping(value = "import/template")
    public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "项目数据导入模板.xlsx";
    		List<ProjectRecords> list = Lists.newArrayList(); 
    		new ExportExcel("项目数据", ProjectRecords.class, 1).setDataList(list).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入模板下载失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
    }
	
	
	
	@RequestMapping("getContractInfo")
	@ResponseBody
	public WorkContractInfo queryContractInfo(WorkContractInfo  contractInfo){
		WorkContractInfo workContractInfo = contractInfoService.get(contractInfo.getId());
		if(workContractInfo==null){
		    return workContractInfo;
        }
		workContractInfo.setConstructionProjectTypeStr(DictUtils.getDictLabel(String.valueOf(workContractInfo.getConstructionProjectType()),"construction_project_type",""));
		if(workContractInfo.getWorkClientInfoList()!=null&&!workContractInfo.getWorkClientInfoList().isEmpty()){
            StringBuilder workClinetInfoIds = new StringBuilder();
            for (WorkClientInfo workClientInfo : workContractInfo.getWorkClientInfoList()) {
                workClinetInfoIds.append(workClientInfo.getId()).append(",");
            }
            workClinetInfoIds.deleteCharAt(workClinetInfoIds.length()-1);
            workContractInfo.setWorkClinetInfoIds(workClinetInfoIds.toString());
        }
		return  workContractInfo;
	}

	//	审批页面
	@RequestMapping(value = "projectRecordsAudit")
	public String workContractInfoAudit(Act act, ProjectRecords projectRecords, Model model) {

		if (act.getProcInsId() != null) {
			if (actTaskService.getProcIns(act.getProcInsId()) != null) {
				act.setProcIns(actTaskService.getProcIns(act.getProcInsId()));
			} else {
				act.setFinishedProcIns(actTaskService.getFinishedProcIns(act.getProcInsId()));
			}
		}
		if (act != null && StringUtils.isNotBlank(act.getTaskId())) {
			projectRecords.setAct(act);
			model.addAttribute("processInstanceId", projectRecords.getProcessInstanceId());
		}
		if (projectRecords!=null&&StringUtils.isNotBlank(projectRecords.getId())) {
            projectRecordsService.queryProjectDetail(projectRecords);
		}
		model.addAttribute("projectRecords", projectRecords);
		return "modules/projectrecord/projectRecordsAudit";
	}

	@RequestMapping(value = "getProcess")
	public String getProcess(ProjectRecords projectRecords, Model model,HttpServletRequest request){
		model.addAttribute("processInstanceId", projectRecords.getProcessInstanceId());
		return "modules/projectrecord/projectRecordsTask";
	}

	@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 {
            ProjectRecords projectRecords = projectRecordsService.get(id);
            if(5==projectRecords.getProjectStatus()){
                addMessage(redirectAttributes, "项目登记已审批通过，无法撤回");
                return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
            }
            projectRecordsService.cancelProcess(projectRecords);
			addMessage(redirectAttributes, "撤回该项目登记成功");
		}catch (Exception e){
			logger.info(e.getMessage());
			addMessage(redirectAttributes, "撤回该项目登记失败");
		}
		return "redirect:" + Global.getAdminPath() + "/project/projectRecords/?repage";
	}

	/**
	 * 查询待办任务
	 *
	 * @param act
	 * @param model
	 * @return
	 */
	@RequestMapping("/toDoList")
	public String queryToList(Act act, Model model) {

		//合同申请流程
		act.setProcDefKey(ActUtils.PD_PROJECTRECORD[0]);
		List<Act> list = actTaskService.todoList(act);
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();
		List<Activity> activities = activityService.groupByActivityMenu("7854872f45b84acd893010e66a3db2c8",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(actTaskService.todoList(act));
		}

		Role role = UserUtils.getSelectRole().get(0);
		List<ProjectRecords> lists = new ArrayList<ProjectRecords>();
		for (Act a : list) {
			if (a.getTask().getTaskDefinitionKey()!=null) {
				ProjectRecords projectRecords = projectRecordsService.getByProcessInstanceId(a.getProcInsId());
				if (projectRecords==null){continue;}
				projectRecordsService.queryContractInfos(projectRecords);
				projectRecords.setAuditType("项目登记");
				if(projectRecords.getProjectStatus()!= ProjectStatusEnum.RECALL.getValue()) {
					User user1 = UserUtils.get(projectRecords.getCreateBy().getId());
					if (projectRecords != null && user1.getCompany().getId().equals(companyId)) {
						projectRecords.setCreateBy(user1);
						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());
							}
						}
						projectRecords.setAct(a);
						lists.add(projectRecords);
					}
				}
			}
		}

		/*------变更--------*/
		act.setProcDefKey("projectAlter");
		List<Act> list3 = actTaskService.todoList(act);
		Office office3 = UserUtils.getSelectCompany();
		String companyId3 = office3==null?"":office3.getId();
		List<Activity> activities3 = activityService.groupByActivityMenu("807c6d4b5623474792fe78ff1fd1cdff",companyId3);
		for (Activity activity:activities3){
			act.setProcDefKey(activity.getProcessKey());
			list3.addAll(actTaskService.todoList(act));
		}

		for (Act a : list3) {
			ProjectRecords projectRecords = projectRecordsService.getByAlterProcessInstanceId(a.getTask().getProcessInstanceId());
			if (projectRecords!=null){
				projectRecordsService.queryContractInfos(projectRecords);
			}
			if (projectRecords != null && projectRecords.getCompany().getId().equals(companyId3)&& projectRecords.getProjectStatus()==ProjectStatusEnum.ON_CHANGE.getValue()) {
				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());
					}
				}
				projectRecords.setAct(a);
				projectRecords.setAuditType("项目变更");
				lists.add(projectRecords);
			}
		}

		//排除 重新申请|撤销
		Iterator<ProjectRecords> it = lists.iterator();
		while(it.hasNext()){
			ProjectRecords w = it.next();
			if(w.getAct()!=null && w.getAct().getTaskDefKey().equals("reapply")){
				it.remove();
			}
		}

		model.addAttribute("list", lists);
		return "modules/projectrecord/projectRecordsToDoList";
	}

	/**
	 * 审批
	 * @param projectRecords
	 * @param model
	 * @param upload_files
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping("saveAudit")
	public String saveAudit(ProjectRecords projectRecords, Model model,
							@RequestParam(value = "upload_files", required = false) MultipartFile[] upload_files,
							RedirectAttributes redirectAttributes) {
		String home = projectRecords.getHome();
		try {
			String taskDefKey = projectRecords.getAct().getTaskDefKey();
			//当状态为未通过时，重新修改数据
			if ("modifyApply".equals(taskDefKey)) {
				projectRecords.getAct().setComment("重新申请");
			}
			List<User> users = UserUtils.getByProssType(projectRecords.getProcessInstanceId(),1);
			String flag = projectRecords.getAct().getFlag();
			if ("yes".equals(flag) && (users==null || users.size()==0)){
				addMessage(redirectAttributes, "审批失败,审批人为空,请联系管理员！");
			}else {
				String str = projectRecordsService.auditSave(projectRecords,users);
				addMessage(redirectAttributes, str);
			}
		}catch (Exception e){
			addMessage(redirectAttributes, "项目登记流程审批失败");
		}

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

	/**
	 * 查询已办列表
	 * @return
	 */
	@RequestMapping("/queryCompleteList")
	public String queryCompleteList(Act act,HttpServletRequest request,HttpServletResponse response,Model model){
		act.setProcDefKey("projectAudit");
		List<ProjectRecords> list = projectRecordsService.historicList(act);
		Office office = UserUtils.getSelectCompany();
		String companyId = office==null?"":office.getId();
		List<Activity> activities = activityService.groupByActivityMenu("7854872f45b84acd893010e66a3db2c8",companyId);
		for (Activity activity:activities){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(projectRecordsService.historicList(act));
		}

		//合同变更
		act.setProcDefKey("projectAlter");
		List<Activity> activities3 = activityService.groupByActivityMenu("807c6d4b5623474792fe78ff1fd1cdff",companyId);
		for (Activity activity:activities3){
			act.setProcDefKey(activity.getProcessKey());
			list.addAll(projectRecordsService.historicAlterList(act));
		}
		model.addAttribute("list",list);
		return "modules/projectrecord/projectRecordsHistoricList";
	}

	/**
	 * 选择合同
	 */
	@RequestMapping(value = "selectcontract")
	public String selectcontractId(WorkContractInfo contract, String url,String type,String isTotal, String fieldLabels, String fieldKeys, String searchLabel, String searchKey, HttpServletRequest request, HttpServletResponse response, Model model) {
		if(!"1".equals(UserUtils.getSelectCompany().getId())){
			contract.setOfficeId(UserUtils.getSelectOffice().getId());
			contract.setChargeCompany(UserUtils.getSelectOffice().getId());
			contract.setCreateBy(UserUtils.getUser());
		}
		contract.setContractState("5");
		Page<WorkContractInfo> page = contractInfoService.findPageReceipts(new Page<WorkContractInfo>(request, response),  contract);
		try {
			fieldLabels = URLDecoder.decode(fieldLabels, "UTF-8");
			fieldKeys = URLDecoder.decode(fieldKeys, "UTF-8");
			searchLabel = URLDecoder.decode(searchLabel, "UTF-8");
			searchKey = URLDecoder.decode(searchKey, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		model.addAttribute("labelNames", fieldLabels.split("\\|"));
		model.addAttribute("labelValues", fieldKeys.split("\\|"));
		model.addAttribute("fieldLabels", fieldLabels);
		model.addAttribute("fieldKeys", fieldKeys);
		model.addAttribute("url", url);
		model.addAttribute("searchLabel", searchLabel);
		model.addAttribute("searchKey", searchKey);
		model.addAttribute("type", type);
		model.addAttribute("isTotal", isTotal);
		model.addAttribute("obj", contract);
		model.addAttribute("page", page);
		return "modules/sys/gridselectContractDetail";
	}

	@RequestMapping(value = "detailList")
    @RequiresPermissions("project:projectRecordsDetail:list")
    public String detailList(ProjectRecords projectRecords, HttpServletRequest request, HttpServletResponse response, Model model) {
        if(UserUtils.isManager()){
            model.addAttribute("flag","1");
        }
        Page<ProjectRecords> page = projectRecordsService.findPageDetail(new Page<ProjectRecords>(request, response), projectRecords);
        model.addAttribute("page", page);
        return "modules/projectrecord/projectRecordsDetailList";
    }

    /**
     * 导出excel文件
     */
    @RequiresPermissions("project:projectRecordsDetail:export")
    @RequestMapping(value = "exportDetail", method=RequestMethod.POST)
    public String exportDetailFile(ProjectRecords projectRecords, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
        try {
            String fileName = "项目"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            Page<ProjectRecords> page = projectRecordsService.findPageDetail(new Page<ProjectRecords>(request, response, -1), projectRecords);
            new ExportExcel("项目", ProjectRecords.class).setDataList(page.getList()).write(response, fileName).dispose();
            return null;
        } catch (Exception e) {
            addMessage(redirectAttributes, "导出项目记录失败！失败信息："+e.getMessage());
        }
        return "redirect:"+Global.getAdminPath()+"/project/projectRecords/?repage";
    }

    /**
     * 下载导入项目数据模板
     */
    @RequiresPermissions("project:projectRecords:edit")
    @RequestMapping(value = "downloadTemplate")
    public void downloadTemplate(HttpServletRequest request,HttpServletResponse response) {
        try {
            new OSSClientUtil().downByStream(template_path,template_name,response,request.getHeader("USER-AGENT"));
        } catch (Exception e) {
            logger.error("项目计划模板下载失败！",e);
        }
    }
}