package com.zcloud.controller.bus;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
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 org.springframework.web.servlet.ModelAndView;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.entity.system.Dictionaries;
import com.zcloud.service.bus.IdeRepositoryService;
import com.zcloud.service.bus.ResourceCorpService;
import com.zcloud.service.bus.RiskPointService;
import com.zcloud.service.system.DictionariesService;
import com.zcloud.util.Const;
import com.zcloud.util.DateUtil;
import com.zcloud.util.FileDownload;
import com.zcloud.util.FileUpload;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.ObjectExcelRead;
import com.zcloud.util.ObjectExcelView;
import com.zcloud.util.PathUtil;
import com.zcloud.util.Tools;

/**
 * 说明：辨识部位资源库
 * 作者：luoxiaobao
 * 时间：2021-03-22
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/iderepository")
public class IdeRepositoryController extends BaseController {

	@Autowired
	private IdeRepositoryService iderepositoryService;

	@Autowired
	private ResourceCorpService resourceCorpService;

	@Autowired
	private RiskPointService riskPointService;

	@Autowired
	private DictionariesService dictionariesService;

	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/add")
	@RequiresPermissions("iderepository:add")
	@ResponseBody
	public Object add() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("IDEREPOSITORY_ID", this.get32UUID());	//主键
		pd.put("ISDELETE", "0");	//是否删除 0 未删除  1已删除
		pd.put("OPERATOR", Jurisdiction.getUsername());	//操作人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//操作时间
		pd.put("CREATOR", Jurisdiction.getUsername());	//创建人
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));	//创建时间
		pd.put("RISK_DESCR",pd.getString("RISK_DESCR").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
		pd.put("MEASURES",pd.getString("MEASURES").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
		pd.put("EME_MEASURES",pd.getString("EME_MEASURES").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
		pd.put("RISKUNIT",pd.getString("RISKUNIT").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
		pd.put("IDENTIFICATION",pd.getString("IDENTIFICATION").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
		List<PageData> iderep = iderepositoryService.selectrepeat(pd);  //通过存在风险、管控措施、应急处置措施查重
		if(iderep.size()==0){
			iderepositoryService.save(pd);
		} else {
			map.put("ISTRUE","1");
		}
		map.put("result", errInfo);
		return map;
	}

	/**删除
	 * @param out
	 * @throws Exception
	 */
	@RequestMapping(value="/delete")
	@RequiresPermissions("iderepository:del")
	@ResponseBody
	public Object delete() throws Exception{
		Map<String,String> map = new HashMap<String,String>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		iderepositoryService.delete(pd);
		map.put("result", errInfo);				//返回结果
		return map;
	}

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/edit")
	@RequiresPermissions("iderepository:edit")
	@ResponseBody
	public Object edit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		List<PageData> iderep = iderepositoryService.selectrepeat(pd);  //通过存在风险、管控措施、应急处置措施查重
		if(iderep.size()==0){
			iderepositoryService.edit(pd);
		} else {
			map.put("ISTRUE","1");
		}
		map.put("result", errInfo);
		return map;
	}

	/**修改
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/editStatus")
	@RequiresPermissions("iderepository:edit")
	@ResponseBody
	public Object editStatus() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		List<PageData> iderep = iderepositoryService.selectrepeat(pd);  //通过存在风险、管控措施、应急处置措施查重
		if(iderep.size()==0){
			iderepositoryService.editStatus(pd);
		} else {
			map.put("ISTRUE","1");
		}
		map.put("result", errInfo);
		return map;
	}

	/**列表
	 * @param page
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	@RequiresPermissions("iderepository:list")
	@ResponseBody
	public Object list(Page page) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("STATUS", "1");

		page.setPd(pd);
		List<PageData> varList = new ArrayList<>();
		varList = iderepositoryService.reslist(page);	//列出IdeRepository列表
		map.put("varList", varList);
		map.put("page", page);
		map.put("result", errInfo);
		return map;
	}

	 /**去修改页面获取数据
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	@RequiresPermissions("iderepository:edit")
	@ResponseBody
	public Object goEdit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd = iderepositoryService.findById(pd);	//根据ID读取;
		List<String> CORP_TYPEALL = new ArrayList<String>();
		if(pd.get("CORP_TYPE") != null && Tools.notEmpty(pd.get("CORP_TYPE").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE").toString());
		}
		if(pd.get("CORP_TYPE2") != null && Tools.notEmpty(pd.get("CORP_TYPE2").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE2").toString());
		}
		if(pd.get("CORP_TYPE3") != null && Tools.notEmpty(pd.get("CORP_TYPE3").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE3").toString());
		}
		if(pd.get("CORP_TYPE4") != null && Tools.notEmpty(pd.get("CORP_TYPE4").toString())) {
			CORP_TYPEALL.add(pd.get("CORP_TYPE4").toString());
		}
		if(CORP_TYPEALL != null && CORP_TYPEALL.size() > 0) {
			pd.put("industryOption", initDicTree(CORP_TYPEALL.get(CORP_TYPEALL.size()-1)));
		}
		pd.put("INDUSTRYALL", CORP_TYPEALL);
		map.put("pd", pd);
		map.put("result", errInfo);
		return map;
	}

	 /**批量删除
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteAll")
	@RequiresPermissions("iderepository:del")
	@ResponseBody
	public Object deleteAll() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		String RES_IDS = pd.getString("RES_IDS");
		String RISK_IDS = pd.getString("RISK_IDS");
		if(Tools.notEmpty(RES_IDS) || Tools.notEmpty(RISK_IDS)) {
			if(Tools.notEmpty(RES_IDS)){
				String ArrayDATA_IDS[] = RES_IDS.split(",");
				iderepositoryService.deleteAll(ArrayDATA_IDS);
			}
			if(Tools.notEmpty(RISK_IDS)){
				String ArrayDATA_IDS[] = RISK_IDS.split(",");
				riskPointService.resDeleteAll(ArrayDATA_IDS);
			}
			errInfo = "success";
		} else {
			errInfo = "error";
		}
		map.put("result", errInfo);				//返回结果
		return map;
	}

	/**从EXCEL导入到数据库
	 * @param file
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/readExcel")
//	@RequiresPermissions("fromExcel")
	@SuppressWarnings("unchecked")
	@ResponseBody
	@Transactional
	public Object readExcel(@RequestParam(value="FFILE",required=false) MultipartFile file) throws Exception{
		Map<String,String> map = new HashMap<String,String>();
		String errInfo = "success";
		PageData pd = new PageData();
		StringBuffer errorStr = new StringBuffer();
		List<PageData> rList = new ArrayList<PageData>();
		if (null != file && !file.isEmpty()) {


			String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + "ideRepository/"+DateUtil.getDays()+"/";
			String fileName =  FileUpload.fileUp(file, filePath, this.get32UUID());//执行上传
			String fileTyle=fileName.substring(fileName.lastIndexOf("."),fileName.length());
			String ffile = "ideRepository/"+DateUtil.getDays()+"/";
//			String filePath = Const.FILEURL + Const.FILEPATHFILE + ffile;
//    		String fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
//		 	Smb.sshSftp(file, fileName,Const.FILEPATHFILE + ffile);
			List<PageData> listPd = (List)ObjectExcelRead.readExcel(filePath, fileName, 1, 0, 0);			//执行读EXCEL操作,读出的数据导入List 2:从第3行开始；0:从第A列开始；0:第0个sheet
			/**
			 * var0 :行业类型
			 * var1 :风险类型
			 * var2 :风险单元
			 * var3 :辨识部位
			 * var4 :存在风险
			 * var5 :风险分级
			 * var6 :主要管控措施
			 * var7 :事故类型
			 * var8 :事故类型
			 * var9 :事故类型
			 * var10 :事故类型/imgfiles/add
			 * var11 :应急处置措施
			 */

			List<String> header = new ArrayList<>();
			header.add("一级行业类型");header.add("二级行业类型");header.add("三级行业类型");header.add("四级行业类型");header.add("风险单元");header.add("辨识部位");header.add("存在风险");header.add("风险分级");header.add("主要管控措施");
			header.add("事故类型1");header.add("事故类型2");header.add("事故类型3");
			header.add("事故类型4");header.add("应急处置措施");

			List<Dictionaries> levelAll =dictionariesService.listSubDictByParentId("5a81e63ec0e94d919b3138bc01dbef6b");//获取全部的风险等级
			Map<String, Object> levelMapAll = new HashMap<>();
			for (Dictionaries dictionaries : levelAll) {
				levelMapAll.put(Tools.excelHandle(dictionaries.getNAME()), dictionaries);
			}
			List<PageData> wDatas  = new ArrayList<>();
			List<PageData> corpTypeAll =dictionariesService.listAllDictToSelect("f2598ba72e864eadabf0ca4b664d26b9",wDatas);//获取全部的行业类型
			Map<String, Object> corpTypeMapAll = new HashMap<>();
			for (PageData dictionaries : corpTypeAll) {
				corpTypeMapAll.put(Tools.excelHandle(dictionaries.get("name").toString()), dictionaries);
			}

			List<Dictionaries> riskTypeAll =dictionariesService.listSubDictByParentId("a726649082d147d88478283f64529b7b");//获取全部的风险类型
			Map<String, Object> riskTypeMapAll = new HashMap<>();
			for (Dictionaries dictionaries : riskTypeAll) {
				riskTypeMapAll.put(Tools.excelHandle(dictionaries.getNAME()), dictionaries);
			}

			List<Dictionaries> accListAll =dictionariesService.listSubDictByParentId("cee1190ea96a4ca9b7bca81e11f0d0f8");//获取全部的事故类型
			Map<String, Object> accMapList = new HashMap<>();
			for (Dictionaries dictionaries : accListAll) {
				accMapList.put(Tools.excelHandle(dictionaries.getNAME()), dictionaries);
			}

			int succeeNum = 1;
			if(listPd.size()<1) {
				map.put("result", "error");				//返回结果
				map.put("resultStr", "Excel数据为空，请检查数据后，重新上传！");
				return map;
			}
			for(PageData lpd:listPd) {
				succeeNum ++;

				for(int i=0;i<header.size();i++) {
					if(i>=10 && i<=12) {
						continue;
					}
					if(!lpd.containsKey("var"+i)) {
						errorStr.append("第"+succeeNum+"行的\""+header.get(i)+"\"无数据;\n");
						continue;
					}
					if(Tools.isEmpty(lpd.get("var"+i))) {
						errorStr.append("第"+succeeNum+"行的\""+header.get(i)+"\"无数据;\n");
						continue;
					}
				}

				String corpTypeVar = Tools.isEmpty(lpd.get("var0"))?"":Tools.excelHandle(lpd.get("var0"));
				String corpType2Var = Tools.isEmpty(lpd.get("var1"))?"":Tools.excelHandle(lpd.get("var1"));
				String corpType3Var = Tools.isEmpty(lpd.get("var2"))?"":Tools.excelHandle(lpd.get("var2"));
				String corpType4Var = Tools.isEmpty(lpd.get("var3"))?"":Tools.excelHandle(lpd.get("var3"));
//				String risktypeVar = Tools.isEmpty(lpd.get("var4"))?"":Tools.excelHandle(lpd.get("var4"));
				String riskVar = Tools.isEmpty(lpd.get("var4"))?"":Tools.excelHandle(lpd.get("var4"));
				String identificationVar = Tools.isEmpty(lpd.get("var5"))?"":Tools.excelHandle(lpd.get("var5"));
				String riskPointVar = Tools.isEmpty(lpd.get("var6"))?"":Tools.excelHandle(lpd.get("var6"));
				String levelVar = Tools.isEmpty(lpd.get("var7"))?"":Tools.excelHandle(lpd.get("var7"));
				String measuresVar = Tools.isEmpty(lpd.get("var8"))?"":Tools.excelHandle(lpd.get("var8"));

				String accidents7Var = Tools.isEmpty(lpd.get("var9"))?"":Tools.excelHandle(lpd.get("var9"));
				String accidents8Var = Tools.isEmpty(lpd.get("var10"))?"":Tools.excelHandle(lpd.get("var10"));
				String accidents9Var = Tools.isEmpty(lpd.get("var11"))?"":Tools.excelHandle(lpd.get("var11"));
				String accidents10Var = Tools.isEmpty(lpd.get("var12"))?"":Tools.excelHandle(lpd.get("var12"));
				String emeMeasuresVar = Tools.isEmpty(lpd.get("var13"))?"":Tools.excelHandle(lpd.get("var13"));


				if(!levelMapAll.containsKey(levelVar)) {
					errorStr.append("第"+succeeNum+"行的"+header.get(6)+"未找到名称为\""+levelVar+"\"的风险分级"+";\n");
					continue;
				}

				if(!Tools.isEmpty(corpTypeVar)) {
					if(!corpTypeMapAll.containsKey(corpTypeVar)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(0)+"未找到名称为\""+corpTypeVar+"\"的一级行业类型"+";\n");
						continue;
					}
				}
				if(!Tools.isEmpty(corpType2Var)) {
					if(!corpTypeMapAll.containsKey(corpType2Var)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(1)+"未找到名称为\""+corpType2Var+"\"的二级行业类型"+";\n");
						continue;
					}
				}

				if(!Tools.isEmpty(corpType3Var)) {
					if(!corpTypeMapAll.containsKey(corpType3Var)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(2)+"未找到名称为\""+corpType3Var+"\"的三级行业类型"+";\n");
						continue;
					}
				}

				if(!Tools.isEmpty(corpType4Var)) {
					if(!corpTypeMapAll.containsKey(corpType4Var)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(3)+"未找到名称为\""+corpType4Var+"\"的四级行业类型"+";\n");
						continue;
					}
				}

				if(!Tools.isEmpty(accidents7Var)) {
					if(!accMapList.containsKey(accidents7Var)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(9)+"未找到名称为\""+accidents7Var+"\"的事故类型(1)"+";\n");
						continue;
					}
				}
				if(!Tools.isEmpty(accidents8Var)) {
					if(!accMapList.containsKey(accidents8Var)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(10)+"未找到名称为\""+accidents8Var+"\"的事故类型(2)"+";\n");
						continue;
					}
				}
				if(!Tools.isEmpty(accidents9Var)) {
					if(!accMapList.containsKey(accidents9Var)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(11)+"未找到名称为\""+accidents9Var+"\"的事故类型(3)"+";\n");
						continue;
					}
				}
				if(!Tools.isEmpty(accidents10Var)) {
					if(!accMapList.containsKey(accidents10Var)) {
						errorStr.append("第"+succeeNum+"行的"+header.get(12)+"未找到名称为\""+accidents10Var+"\"的事故类型(4)"+";\n");
						continue;
					}
				}

				Dictionaries levelVal = (Dictionaries) levelMapAll.get(levelVar);
				PageData corpTypeVal = (PageData) corpTypeMapAll.get(corpTypeVar);
				PageData corpType2Val = (PageData) corpTypeMapAll.get(corpType2Var);
				PageData corpType3Val = (PageData) corpTypeMapAll.get(corpType3Var);
				PageData corpType4Val = (PageData) corpTypeMapAll.get(corpType4Var);

				String accidentsId = "";
				String accidentsNames ="";
				if(!Tools.isEmpty(accidents7Var)) {
					Dictionaries acc7Val = new Dictionaries();
					acc7Val = (Dictionaries) accMapList.get(accidents7Var);
					accidentsId += ","+acc7Val.getBIANMA();
					accidentsNames +=","+acc7Val.getNAME();
				}
				if(!Tools.isEmpty(accidents8Var)) {
					Dictionaries acc8Val = new Dictionaries();
					acc8Val = (Dictionaries) accMapList.get(accidents8Var);
					accidentsId += ","+acc8Val.getBIANMA();
					accidentsNames +=","+acc8Val.getNAME();
				}
				if(!Tools.isEmpty(accidents9Var)) {
					Dictionaries acc9Val = new Dictionaries();
					acc9Val = (Dictionaries) accMapList.get(accidents9Var);
					accidentsId += ","+acc9Val.getBIANMA();
					accidentsNames +=","+acc9Val.getNAME();
				}
				if(!Tools.isEmpty(accidents10Var)) {
					Dictionaries acc10Val = new Dictionaries();
					acc10Val = (Dictionaries) accMapList.get(accidents10Var);
					accidentsId += ","+acc10Val.getBIANMA();
					accidentsNames +=","+acc10Val.getNAME();
				}
				if(Tools.notEmpty(accidentsId)) {
					accidentsId = accidentsId.substring(1, accidentsId.length());
				}
				if(Tools.notEmpty(accidentsNames)) {
					accidentsNames = accidentsNames.substring(1, accidentsNames.length());
				}
				PageData iderepository = new PageData();
				iderepository.put("RISKUNIT", lpd.getString("var4").replace("\n","").replace(" ",""));
				iderepository.put("IDENTIFICATION", lpd.getString("var5").replace("\n","").replace(" ",""));
				String corpTypeNames ="";
				if(corpTypeVal != null) {
					iderepository.put("CORP_TYPE", corpTypeVal.get("id"));
					corpTypeNames = corpTypeVal.getString("name");
				}
				if(corpType2Val != null) {
					iderepository.put("CORP_TYPE2", corpType2Val.get("id"));
					corpTypeNames += "/"+corpType2Val.getString("name");
				}
				if(corpType3Val != null) {
					iderepository.put("CORP_TYPE3", corpType3Val.get("id"));
					corpTypeNames += "/"+corpType3Val.getString("name");
				}
				if(corpType4Val != null) {
					iderepository.put("CORP_TYPE4", corpType4Val.get("id"));
					corpTypeNames += "/"+corpType4Val.getString("name");
				}
				iderepository.put("CORP_TYPE_NAME", corpTypeNames);

				iderepository.put("RISK_DESCR", riskPointVar);
				iderepository.put("LEVELID", levelVal.getBIANMA());
				iderepository.put("MEASURES", measuresVar);
				iderepository.put("ACCIDENTS", accidentsId);
				iderepository.put("ACCIDENTS_NAME", accidentsNames);
				iderepository.put("EME_MEASURES", emeMeasuresVar);
				iderepository.put("IDEREPOSITORY_ID", this.get32UUID());
				iderepository.put("ISDELETE", "0");
				iderepository.put("RESOURCETYPE", "1");
				iderepository.put("CREATOR", Jurisdiction.getUsername());
				iderepository.put("CREATTIME", DateUtil.date2Str(new Date()));
				iderepository.put("OPERATOR",Jurisdiction.getUsername());
				iderepository.put("OPERATTIME", DateUtil.date2Str(new Date()));

				rList.add(iderepository);

				pd.put("RISK_DESCR",lpd.getString("var6").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));  //替换中文， ； : ） 空格和回车
				pd.put("MEASURES",lpd.getString("var8").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
				pd.put("EME_MEASURES",emeMeasuresVar.replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
				pd.put("RISKUNIT",lpd.getString("var4").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
				pd.put("IDENTIFICATION",lpd.getString("var5").replace("\n","").replace("；",";").replace("，",",").replace("：",":").replace("）",")").replace(" ",""));
				List<PageData> iderep = iderepositoryService.selectrepeat(pd);  //通过存在风险、管控措施、应急处置措施查重
				if(iderep.size()==0){

				} else {
					errorStr.append("第"+succeeNum+"行"+"，数据库中已存在相同的存在风险、管控措施、应急处置措施、辨识部位、风险单元");
					continue;
				}
			}

			if(Tools.isEmpty(errorStr.toString())) {

				for(PageData r:rList) {
					iderepositoryService.save(r);
				}
				errorStr.append("成功导入"+rList.size()+"条数据!");

			}else {

			}
		}
		map.put("result", errInfo);				//返回结果
		map.put("msg",errorStr.toString());				//返回结果
		map.put("resultStr", errorStr.toString());
		return map;
	}
	 /**导出到excel
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/excelModel")
	public void exportExcelModel(HttpServletResponse response) throws Exception{
		FileDownload.fileDownload(response, PathUtil.getProjectpath() + Const.FILEPATHFILE + "ideRepositoryExcelTemplate.xls", "风险辨识资源库模板.xls");
	}
	 /**导出到excel
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/excel")
	@RequiresPermissions("toExcel")
	public ModelAndView exportExcel() throws Exception{
		ModelAndView mv = new ModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		Map<String,Object> dataMap = new HashMap<String,Object>();
		List<String> titles = new ArrayList<String>();
		titles.add("行业类型");	//1
		titles.add("风险类型");	//2
		titles.add("风险单元");	//3
		titles.add("辨识部位");	//4
		titles.add("存在风险");	//5
		titles.add("风险分级");	//6
		titles.add("管控措施");	//7
		titles.add("事故类型");	//8
		titles.add("应急处置措施");	//9
		titles.add("是否删除 0 未删除  1已删除");	//10
		titles.add("资源类型  1  资源库辨识风险 2 自定义辨识风险");	//11
		titles.add("添加人");	//12
		titles.add("创建时间");	//13
		titles.add("修改人");	//14
		titles.add("修改时间");	//15
		dataMap.put("titles", titles);
		List<PageData> varOList = iderepositoryService.listAll(pd);
		List<PageData> varList = new ArrayList<PageData>();
		for(int i=0;i<varOList.size();i++){
			PageData vpd = new PageData();
			vpd.put("var1", varOList.get(i).getString("INDUSTRY"));	    //1
			vpd.put("var2", varOList.get(i).getString("RISKTYPE"));	    //2
			vpd.put("var3", varOList.get(i).getString("RISKUNIT"));	    //3
			vpd.put("var4", varOList.get(i).getString("IDENTIFICATION"));	    //4
			vpd.put("var5", varOList.get(i).getString("RISK_DESCR"));	    //5
			vpd.put("var6", varOList.get(i).getString("LEVELID"));	    //6
			vpd.put("var7", varOList.get(i).getString("MEASURES"));	    //7
			vpd.put("var8", varOList.get(i).getString("ACCIDENTS"));	    //8
			vpd.put("var9", varOList.get(i).getString("EME_MEASURES"));	    //9
			vpd.put("var10", varOList.get(i).getString("ISDELETE"));	    //10
			vpd.put("var11", varOList.get(i).getString("RESOURCETYPE"));	    //11
			vpd.put("var12", varOList.get(i).getString("CREATOR"));	    //12
			vpd.put("var13", varOList.get(i).getString("CREATTIME"));	    //13
			vpd.put("var14", varOList.get(i).getString("OPERATOR"));	    //14
			vpd.put("var15", varOList.get(i).getString("OPERATTIME"));	    //15
			varList.add(vpd);
		}
		dataMap.put("varList", varList);
		ObjectExcelView erv = new ObjectExcelView();
		mv = new ModelAndView(erv,dataMap);
		return mv;
	}

	/**
	 * 初始化数据字典懒加载下拉树
	 * @param dictionaries_id
	 * @return
	 * @throws Exception
	 */
	public List<PageData> initDicTree(String dictionaries_id) throws Exception{
		PageData dic = new PageData();
		dic.put("DICTIONARIES_ID", dictionaries_id);
		dic = dictionariesService.findById(dic);
		dic.put("value", dic.get("DICTIONARIES_ID"));
		dic.put("id", dic.get("DICTIONARIES_ID"));
		dic.put("label", dic.get("NAME"));
		List<PageData> industryOption = dictionariesService.getTreeFromBelow(new ArrayList<PageData>(),dic);
		return industryOption;
	}
}
