package com.jeeplus.modules.filing.constructionStage.web;

import com.google.common.collect.Lists;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.filing.constructionStage.entity.ConstructionStage;
import com.jeeplus.modules.filing.constructionStage.entity.*;
import com.jeeplus.modules.filing.constructionStage.service.ConstructionStageService;
import com.jeeplus.modules.filing.filingImages.service.FilingImagesService;
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.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.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 工程建设阶段Controller
 * @author qy
 * @version 2021-03-24
 */
@Controller
@RequestMapping(value = "${adminPath}/filing/constructionStage")
public class ConstructionStageController extends BaseController {

	@Autowired
	private ConstructionStageService constructionStageService;

	@Autowired
	private FilingImagesService filingImagesService;

	@ModelAttribute
	public ConstructionStage get(@RequestParam(required=false) String id) {
		ConstructionStage entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = constructionStageService.get(id);
		}
		if (entity == null){
			entity = new ConstructionStage();
		}
		return entity;
	}
	
	/**
	 * 工程建设阶段列表页面
	 */
	@RequiresPermissions("test:filing:constructionStage:list")
	@RequestMapping(value = {"list", ""})
	public String list(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/constructionStage/constructionStageList";
	}

	/**
	 * 开竣工管理列表页面
	 */
	@RequiresPermissions("test:filing:startUp:list")
	@RequestMapping(value = "startUp")
	public String startUp(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/startUp/startUpList";
	}

	/**
	 * 查看，增加,开竣工管理阶段表单页面
	 */
	@RequiresPermissions(value={"test:filing:startUp:view","test:filing:startUp:add","test:filing:startUp:edit"},logical=Logical.OR)
	@RequestMapping(value = "startUpForm")
	public String startUpForm(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/startUp/startUpForm";
	}

	/**
	 * 工程进度管理段列表页面
	 */
	@RequiresPermissions("test:filing:projectSchedule:list")
	@RequestMapping(value = "projectSchedule")
	public String projectSchedule(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/projectSchedule/projectScheduleList";
	}

	/**
	 * 查看，增加,工程进度管理段表单页面
	 */
	@RequiresPermissions(value={"test:filing:projectSchedule:view","test:filing:projectSchedule:add","test:filing:projectSchedule:edit"},logical=Logical.OR)
	@RequestMapping(value = "projectScheduleForm")
	public String projectScheduleForm(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/projectSchedule/projectScheduleForm";
	}

	/**
	 * 安全质量管理列表页面
	 */
	@RequiresPermissions("test:filing:safetyQuality:list")
	@RequestMapping(value = "safetyQuality")
	public String safetyQuality(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/safetyQuality/safetyQualityList";
	}

	/**
	 * 查看，增加,安全质量管理表单页面
	 */
	@RequiresPermissions(value={"test:filing:safetyQuality:view","test:filing:safetyQuality:add","test:filing:safetyQuality:edit"},logical=Logical.OR)
	@RequestMapping(value = "safetyQualityForm")
	public String safetyQualityForm(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/safetyQuality/safetyQualityForm";
	}

	/**
	 * 造价管理阶段列表页面
	 */
	@RequiresPermissions("test:filing:costManagment:list")
	@RequestMapping(value = "costManagment")
	public String costManagment(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/costManagment/costManagmentList";
	}

	/**
	 * 查看，增加,造价管理阶段表单页面
	 */
	@RequiresPermissions(value={"test:filing:costManagment:view","test:filing:costManagment:add","test:filing:costManagment:edit"},logical=Logical.OR)
	@RequestMapping(value = "costManagmentForm")
	public String costManagmentForm(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/costManagment/costManagmentForm";
	}

	/**
	 * 质量管理阶段列表页面
	 */
	@RequiresPermissions("test:filing:qulityAssurance:list")
	@RequestMapping(value = "qulityAssurance")
	public String qulityAssurance(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/qulityAssurance/qulityAssuranceList";
	}

	/**
	 * 查看，增加,质量管理阶段表单页面
	 */
	@RequiresPermissions(value={"test:filing:qulityAssurance:view","test:filing:qulityAssurance:add","test:filing:qulityAssurance:edit"},logical=Logical.OR)
	@RequestMapping(value = "qulityAssuranceForm")
	public String qulityAssuranceForm(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/qulityAssurance/qulityAssuranceForm";
	}

	/**
	 * 安全管理阶段列表页面
	 */
	@RequiresPermissions("test:filing:securityManagment:list")
	@RequestMapping(value = "securityManagment")
	public String securityManagment(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/securityManagment/securityManagmentList";
	}

	/**
	 * 查看，增加,安全管理阶段表单页面
	 */
	@RequiresPermissions(value={"test:filing:securityManagment:view","test:filing:securityManagment:add","test:filing:securityManagment:edit"},logical=Logical.OR)
	@RequestMapping(value = "securityManagmentForm")
	public String securityManagmentForm(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/securityManagment/securityManagmentForm";
	}

	/**
	 * 其他阶段列表页面
	 */
	@RequiresPermissions("test:filing:projectOther:list")
	@RequestMapping(value = "projectOther")
	public String projectOther(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/projectOther/projectOtherList";
	}

	/**
	 * 查看，增加,其他阶段表单页面
	 */
	@RequiresPermissions(value={"test:filing:projectOther:view","test:filing:projectOther:add","test:filing:projectOther:edit"},logical=Logical.OR)
	@RequestMapping(value = "projectOtherForm")
	public String projectOtherForm(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/projectOther/projectOtherForm";
	}

	/**
	 * 工程建设阶段列表数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:constructionStage:list")
	@RequestMapping(value = "data")
	public Map<String, Object> data(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ConstructionStage> page = constructionStageService.findPage(new Page<ConstructionStage>(request, response,-1), constructionStage);
		return getBootstrapData(page);
	}

	/**
	 * 查看，增加,工程建设阶段表单页面
	 */
	@RequiresPermissions(value={"test:filing:constructionStage:view","test:filing:constructionStage:add","test:filing:constructionStage:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(ConstructionStage constructionStage, Model model) {
		model.addAttribute("constructionStage", constructionStage);
		return "modules/filing/constructionStage/constructionStageForm";
	}

	
	/**
	 * 保存工程建设阶段
	 */
	@ResponseBody
	@RequiresPermissions(value={"test:filing:constructionStage:add","test:filing:constructionStage:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public AjaxJson save(ConstructionStage constructionStage, Model model) throws Exception{
		AjaxJson j = new AjaxJson();
		/**
		 * 后台hibernate-validation插件校验
		 */
		String errMsg = beanValidator(constructionStage);
		if (StringUtils.isNotBlank(errMsg)){
			j.setSuccess(false);
			j.setMsg(errMsg);
			return j;
		}
		//新增或编辑表单保存
		constructionStageService.save(constructionStage);//保存
		j.setSuccess(true);
		j.setMsg("保存工程建设阶段成功");
		return j;
	}

	/**
	 * 保存工程建设阶段
	 */
	@ResponseBody
	@RequiresPermissions(value={"test:filing:constructionStage:add","test:filing:constructionStage:edit"},logical=Logical.OR)
	@RequestMapping(value = "updateSave")
	public AjaxJson updateSave(ConstructionStage constructionStage, Model model) throws Exception{
		AjaxJson j = new AjaxJson();
		/**
		 * 后台hibernate-validation插件校验
		 */
		String errMsg = beanValidator(constructionStage);
		if (StringUtils.isNotBlank(errMsg)){
			j.setSuccess(false);
			j.setMsg(errMsg);
			return j;
		}
		//新增或编辑表单保存
		constructionStageService.save(constructionStage);//保存
		j.setSuccess(true);
		j.setMsg("保存工程建设阶段成功");
		return j;
	}


	/**
	 * 删除工程建设阶段
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:constructionStage:del")
	@RequestMapping(value = "delete")
	public AjaxJson delete(ConstructionStage constructionStage) {
		AjaxJson j = new AjaxJson();
		constructionStageService.delete(constructionStage);
		j.setMsg("删除工程建设阶段成功");
		return j;
	}
	
	/**
	 * 批量删除工程建设阶段
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:constructionStage:del")
	@RequestMapping(value = "deleteAll")
	public AjaxJson deleteAll(String ids) {
		AjaxJson j = new AjaxJson();
		String idArray[] =ids.split(",");
		for(String id : idArray){
			constructionStageService.delete(constructionStageService.get(id));
		}
		j.setMsg("删除工程建设阶段成功");
		return j;
	}
	
	/**
	 * 导出excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:constructionStage:export")
    @RequestMapping(value = "export")
    public AjaxJson exportFile(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
            String fileName = "工程建设阶段"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
    		new ExportExcel("工程建设阶段", ConstructionStage.class).setDataList(returnList).write(response, fileName).dispose();
    		j.setSuccess(true);
    		j.setMsg("导出成功！");
    		return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出工程建设阶段记录失败！失败信息："+e.getMessage());
		}
			return j;
    }

	/**
	 * 导出excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:startUp:export")
	@RequestMapping(value = "exportStartUp")
	public AjaxJson exportStartUp(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "开竣工管理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
			new ExportExcel("开竣工管理", StartUP.class).setDataList(returnList).write(response, fileName).dispose();
			j.setSuccess(true);
			j.setMsg("导出成功！");
			return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出开竣工管理记录失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导出excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:projectSchedule:export")
	@RequestMapping(value = "exportProjectSchedule")
	public AjaxJson exportProjectSchedule(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "工程进度管理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
			new ExportExcel("工程进度管理", ProjectSchedule.class).setDataList(returnList).write(response, fileName).dispose();
			j.setSuccess(true);
			j.setMsg("导出成功！");
			return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出工程进度管理记录失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导出安全质量管理excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:safetyQuality:export")
	@RequestMapping(value = "exportSafetyQuality")
	public AjaxJson exportSafetyQuality(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "安全质量管理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
			new ExportExcel("安全质量管理", SafetyQuality.class).setDataList(returnList).write(response, fileName).dispose();
			j.setSuccess(true);
			j.setMsg("导出成功！");
			return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出安全质量管理记录失败！失败信息："+e.getMessage());
		}
		return j;
	}


	/**
	 * 导出造价管理excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:costManagment:export")
	@RequestMapping(value = "exportCostManagment")
	public AjaxJson exportCostManagment(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "造价管理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
			new ExportExcel("造价管理", CostManagment.class).setDataList(returnList).write(response, fileName).dispose();
			j.setSuccess(true);
			j.setMsg("导出成功！");
			return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出造价管理记录失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导出质量管理excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:qulityAssurance:export")
	@RequestMapping(value = "exportQulityAssurance")
	public AjaxJson exportQulityAssurance(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "质量管理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
			new ExportExcel("质量管理", QulityAssurance.class).setDataList(returnList).write(response, fileName).dispose();
			j.setSuccess(true);
			j.setMsg("导出成功！");
			return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出质量管理记录失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导出安全管理excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:securityManagment:export")
	@RequestMapping(value = "exportSecurityManagment")
	public AjaxJson exportSecurityManagment(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "安全管理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
			new ExportExcel("安全管理", SecurityManagment.class).setDataList(returnList).write(response, fileName).dispose();
			j.setSuccess(true);
			j.setMsg("导出成功！");
			return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出安全管理记录失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导出其他excel文件
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:projectOther:export")
	@RequestMapping(value = "exportProjectOther")
	public AjaxJson exportProjectOther(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "其他"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
			//查询所有父级的信息
			List<ConstructionStage> list = constructionStageService.findList(constructionStage);
			List<ConstructionStage> returnList = new ArrayList<>();
			//根据父级，查询所有子级的信息
			for (ConstructionStage a :
					list) {
				List<ConstructionStage> childList = constructionStageService.findChildList(a);
				returnList.add(a);
				for (ConstructionStage b :
						childList) {
					returnList.add(b);
				}
			}
			new ExportExcel("其他", ProjectOther.class).setDataList(returnList).write(response, fileName).dispose();
			j.setSuccess(true);
			j.setMsg("导出成功！");
			return j;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导出其他记录失败！失败信息："+e.getMessage());
		}
		return j;
	}

    @ResponseBody
    @RequestMapping(value = "detail")
	public Map<String, Object> detail(ConstructionStage constructionStage, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ConstructionStage> page = constructionStageService.findChildPage(new Page<ConstructionStage>(request, response), constructionStage);
		return getBootstrapData(page);
	}
	

	/**
	 * 导入Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:constructionStage:import")
    @RequestMapping(value = "import")
   	public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<ConstructionStage> list = ei.getDataList(ConstructionStage.class);
			for (ConstructionStage constructionStage :
					list) {
				constructionStageService.save(constructionStage);
			}
			j.setMsg( "已成功导入工程建设阶段记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入工程建设阶段失败！失败信息："+e.getMessage());
		}
		return j;
    }


	/**
	 * 导入开竣工管理Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:startUp:import")
	@RequestMapping(value = "importStartUp")
	public AjaxJson importStartUp(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<StartUP> list = ei.getDataList(StartUP.class);
			for (StartUP startUP :
					list) {
				constructionStageService.startUpSave(startUP);
			}
			j.setMsg( "已成功导入开竣工管理阶段记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入开竣工管理失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导入造价管理阶段Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:costManagment:import")
	@RequestMapping(value = "importCostManagment")
	public AjaxJson importCostManagment(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<CostManagment> list = ei.getDataList(CostManagment.class);
			for (CostManagment entity :
					list) {
				constructionStageService.costManagmentSave(entity);
			}
			j.setMsg( "已成功导入造价管理阶段记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入造价管理阶段失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导入其他阶段Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:projectOther:import")
	@RequestMapping(value = "importProjectOther")
	public AjaxJson importProjectOther(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<ProjectOther> list = ei.getDataList(ProjectOther.class);
			for (ProjectOther entity :
					list) {
				constructionStageService.projectOtherSave(entity);
			}
			j.setMsg( "已成功导入其他阶段记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入其他阶段失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导入质量管理`Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:qulityAssurance:import")
	@RequestMapping(value = "importQulityAssurance")
	public AjaxJson importQulityAssurance(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<QulityAssurance> list = ei.getDataList(QulityAssurance.class);
			for (QulityAssurance entity :
					list) {
				constructionStageService.qulityAssuranceSave(entity);
			}
			j.setMsg( "已成功导入质量管理阶段记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入质量管理阶段失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导入安全质量管理Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:safetyQuality:import")
	@RequestMapping(value = "importSafetyQuality")
	public AjaxJson importSafetyQuality(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<SafetyQuality> list = ei.getDataList(SafetyQuality.class);
			for (SafetyQuality entity :
					list) {
				constructionStageService.safetyQualitySave(entity);
			}
			j.setMsg( "已成功导入安全质量管理记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入安全质量管理失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导入安全管理Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:securityManagment:import")
	@RequestMapping(value = "importSecurityManagment")
	public AjaxJson importSecurityManagment(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<SecurityManagment> list = ei.getDataList(SecurityManagment.class);
			for (SecurityManagment entity :
					list) {
				constructionStageService.securityManagmentSave(entity);
			}
			j.setMsg( "已成功导入安全管理记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入安全管理失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 导入工程进度管理Excel数据
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:projectSchedule:import")
	@RequestMapping(value = "importProjectSchedule")
	public AjaxJson importProjectSchedule(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
		AjaxJson j = new AjaxJson();
		try {
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<ProjectSchedule> list = ei.getDataList(ProjectSchedule.class);
			for (ProjectSchedule projectSchedule :
					list) {
				constructionStageService.projectScheduleSave(projectSchedule);
			}
			j.setMsg( "已成功导入工程进度管理记录");
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("导入工程进度管理失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 下载导入工程建设阶段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:constructionStage:import")
    @RequestMapping(value = "import/template")
     public AjaxJson importFileTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
            String fileName = "工程建设阶段数据导入模板.xlsx";
    		List<ConstructionStage> list = Lists.newArrayList(); 
    		new ExportExcel("工程建设阶段数据", ConstructionStage.class, 1).setDataList(list).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
    }

	/**
	 * 下载导入造价管理阶段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:costManagment:import")
	@RequestMapping(value = "costManagment/template")
	public AjaxJson importCostManagmentTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "造价管理导入模板.xlsx";
			List<ConstructionStage> list = Lists.newArrayList();
			new ExportExcel("造价管理阶段数据", CostManagment.class, 1).setDataList(list).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 下载导入其他阶段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:projectOther:import")
	@RequestMapping(value = "projectOther/template")
	public AjaxJson importProjectOtherTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "其他导入模板.xlsx";
			List<ConstructionStage> list = Lists.newArrayList();
			new ExportExcel("其他阶段数据", ProjectOther.class, 1).setDataList(list).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 下载导入工程进度管理阶段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:projectSchedule:import")
	@RequestMapping(value = "projectSchedule/template")
	public AjaxJson importProjectScheduleTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "工程进度管理导入模板.xlsx";
			List<ConstructionStage> list = Lists.newArrayList();
			new ExportExcel("工程进度管理阶段数据", ProjectSchedule.class, 1).setDataList(list).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 下载导入质量管理阶段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:qulityAssurance:import")
	@RequestMapping(value = "qulityAssurance/template")
	public AjaxJson importQulityAssuranceTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "质量管理导入模板.xlsx";
			List<ConstructionStage> list = Lists.newArrayList();
			new ExportExcel("质量管理阶段数据", QulityAssurance.class, 1).setDataList(list).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 下载导入安全质量管理段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:safetyQuality:import")
	@RequestMapping(value = "safetyQuality/template")
	public AjaxJson importSafetyQualityTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "安全质量管理导入模板.xlsx";
			List<ConstructionStage> list = Lists.newArrayList();
			new ExportExcel("安全质量管理阶段数据", SafetyQuality.class, 1).setDataList(list).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 下载导入安全管理段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:securityManagment:import")
	@RequestMapping(value = "securityManagment/template")
	public AjaxJson importSecurityManagmentTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "安全管理导入模板.xlsx";
			List<ConstructionStage> list = Lists.newArrayList();
			new ExportExcel("安全管理阶段数据", SecurityManagment.class, 1).setDataList(list).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
	}

	/**
	 * 下载导入开竣工管理段数据模板
	 */
	@ResponseBody
	@RequiresPermissions("test:filing:startUP:import")
	@RequestMapping(value = "startUP/template")
	public AjaxJson importStartUpTemplate(HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		try {
			String fileName = "开竣工管理导入模板.xlsx";
			List<ConstructionStage> list = Lists.newArrayList();
			new ExportExcel("开竣工管理阶段数据", StartUP.class, 1).setDataList(list).write(response, fileName).dispose();
			return null;
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg( "导入模板下载失败！失败信息："+e.getMessage());
		}
		return j;
	}
}