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

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
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.exampleeconomics.entity.ExampleEconomics;
import com.jeeplus.modules.exampleeconomics.service.ExampleEconomicsService;
import com.jeeplus.modules.exampleexpend.entity.ExampleExpend;
import com.jeeplus.modules.exampleexpend.service.ExampleExpendService;
import com.jeeplus.modules.exampleproject.entity.ExampleProject;
import com.jeeplus.modules.exampleproject.service.ExampleProjectService;
import com.jeeplus.modules.examplesingle.entity.ExampleSingle;
import com.jeeplus.modules.examplesingle.service.ExampleSingleService;
import com.jeeplus.modules.sys.utils.DictUtils;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workexample.entity.WorkExample;
import com.jeeplus.modules.workexample.entity.WorkExampleIndices;
import com.jeeplus.modules.workexample.service.WorkExampleIndicesService;
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 杨帆
 * @version 2018-08-27
 */
@Controller
@RequestMapping(value = "${adminPath}/workexample/workExampleIndices")
public class WorkExampleIndicesController extends BaseController {

	@Autowired
	private WorkExampleIndicesService workExampleIndicesService;
	@Autowired
	private ExampleSingleService exampleSingleService;
	@Autowired
	private ExampleProjectService exampleProjectService;
	@Autowired
	private ExampleExpendService exampleExpendService;
	@Autowired
	private ExampleEconomicsService exampleEconomicsService;
	@ModelAttribute
	public WorkExampleIndices get(@RequestParam(required=false) String id) {
		WorkExampleIndices entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workExampleIndicesService.get(id);
		}
		if (entity == null){
			entity = new WorkExampleIndices();
		}
		return entity;
	}
	
	/**
	 * 指标字典列表页面
	 */
	@RequiresPermissions("workexample:workExampleIndices:list")
	@RequestMapping(value = {"list", ""})
	public String list(WorkExampleIndices workExampleIndices, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<WorkExampleIndices> list = workExampleIndicesService.findLists(workExampleIndices);
		if(list==null || list.size()==0){
            list = workExampleIndicesService.findList(workExampleIndices);
        }
		model.addAttribute("list", list);
		return "modules/workexample/workExampleIndicesList";
	}

	/**
	 * 查看，增加，编辑指标字典表单页面
	 */
	//@RequiresPermissions(value={"workexample:workExampleIndices:view","workexample:workExampleIndices:add","workexample:workExampleIndices:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(WorkExampleIndices workExampleIndices, Model model) {
		if (StringUtils.isNotBlank(workExampleIndices.getView()) && workExampleIndices.getView().equals("view")){
			model.addAttribute("edit", false);
		}else {
			model.addAttribute("edit", true);
		}
		String type = workExampleIndices.getType();
		if (StringUtils.isNotBlank(workExampleIndices.getView()) && workExampleIndices.getView().equals("save")){
			Integer orderNum = workExampleIndicesService.getOrderNum(workExampleIndices.getId());
			WorkExampleIndices parent = new WorkExampleIndices(workExampleIndices.getId());
			String parentIds = workExampleIndices.getParentIds();
			String num = "";
			if (orderNum==null || orderNum<1){
				num = workExampleIndices.getOrderNum()+"01";
			}else {
				num = (orderNum+1)+"";
			}
			workExampleIndices = new WorkExampleIndices();
			workExampleIndices.setOneItems("2");
			workExampleIndices.setIsDisable("0");
			workExampleIndices.setOrderNum(num);
			workExampleIndices.setParent(parent);
			workExampleIndices.setParentIds(parentIds+parent.getId()+",");
			model.addAttribute("workExampleIndices", workExampleIndices);
			if (StringUtils.isNotBlank(type) && (type.equals("2")|| type.equals("3"))){
				//添加指标
				return "modules/workexample/workExampleIndicesSave";
			}else {
				//添加项
				return "modules/workexample/workExampleIndicesAdd";
			}
		}else {
			model.addAttribute("workExampleIndices", workExampleIndices);
			if (StringUtils.isNotBlank(type) && (type.equals("7")|| type.equals("8"))){	//修改项
				return "modules/workexample/workExampleIndicesAdd";
			}else {
				if (workExampleIndices.getType().equals("4")){
					workExampleIndices.setView("1");
				}else if (workExampleIndices.getType().equals("5")){
					workExampleIndices.setView("2");
				}else {
					workExampleIndices.setView("3");
				}
				//添加项
				return "modules/workexample/workExampleIndicesSave";
			}
			//model.addAttribute("workExampleIndices", workExampleIndices);
			//return "modules/workexample/workExampleIndicesForm";
		}
	}
	/**
	 * 保存指标字典
	 */
	//@RequiresPermissions(value={"workexample:workExampleIndices:add","workexample:workExampleIndices:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(WorkExampleIndices workExampleIndices, Model model, RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, workExampleIndices)){
			return form(workExampleIndices, model);
		}
		WorkExampleIndices parent = workExampleIndicesService.get(workExampleIndices.getParent().getId());
		if (parent.getType().equals("1")){
			workExampleIndices.setType("7");
		}else if (parent.getType().equals("2")){
			workExampleIndices.setType("3");
		}else if (parent.getType().equals("3")){
			if (workExampleIndices.getView().equals("1")){
				workExampleIndices.setType("4");
			}else if (workExampleIndices.getView().equals("2")){
				workExampleIndices.setType("5");
			}else {
				workExampleIndices.setType("6");
			}
		}else if (parent.getType().equals("7")){
			workExampleIndices.setType("8");
		}else {
			workExampleIndices.setType("7");
		}
		if(!workExampleIndices.getIsNewRecord()){//编辑表单保存
			WorkExampleIndices t = workExampleIndicesService.get(workExampleIndices.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(workExampleIndices, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			workExampleIndicesService.save(t);//保存
		}else{//新增表单保存
			workExampleIndices.setCompanyId(UserUtils.getSelectCompany().getId());
			workExampleIndicesService.save(workExampleIndices);//保存
		}
		addMessage(redirectAttributes, "保存指标字典成功");
		return "redirect:"+Global.getAdminPath()+"/workexample/workExampleIndices/?repage";
	}
	/**
	 * 保存指标字典
	 */
	//@RequiresPermissions(value={"workexample:workExampleIndices:add","workexample:workExampleIndices:edit"},logical=Logical.OR)
	@RequestMapping(value = "saveExample")
	@ResponseBody
	public AjaxJson saveExample(String ids, String exampleId, Model model, RedirectAttributes redirectAttributes) throws Exception{
		AjaxJson ajaxJson = new AjaxJson();
		String[] idArr = ids.split(",");
		for (String id:idArr){
			Integer count = workExampleIndicesService.exampleIndicesCount(exampleId,id);
			if (count == null || count==0){
				try {
					workExampleIndicesService.saveExampleIndices(exampleId,id);
					List<WorkExampleIndices> workExampleIndicesList = workExampleIndicesService.findByParentId(id);
					WorkExampleIndices exampleIndices = workExampleIndicesService.get(id);
					if (workExampleIndicesList!=null && workExampleIndicesList.size()!=0){
						for (WorkExampleIndices workExampleIndices:workExampleIndicesList){
							//workExampleIndicesService.saveExampleIndices(exampleId,workExampleIndices.getId());
							//id-指标id    workExampleIndices.getId()-項id  exampleId-项目概况id
							if("1".equals(exampleIndices.getType())){
								//单项工程造价指标
								ExampleSingle exampleSingle = new ExampleSingle();
								exampleSingle.setIndexId(id);
								exampleSingle.setExampleId(exampleId);
								exampleSingle.setExampleIndicesId(workExampleIndices.getId());
								exampleSingle.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
								exampleSingle.setDigits(workExampleIndices.getDecimalCount());
								exampleSingle.setName(workExampleIndices.getName());
								exampleSingle.setId("");
								exampleSingleService.save(exampleSingle);
							}else if("4".equals(exampleIndices.getType())){
								//经济指标
								ExampleEconomics exampleEconomics = new ExampleEconomics();
								exampleEconomics.setIndexId(id);
								exampleEconomics.setExampleId(exampleId);
								exampleEconomics.setExampleindicesId(workExampleIndices.getId());
								exampleEconomics.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
								exampleEconomics.setDigits(workExampleIndices.getDecimalCount());
								exampleEconomics.setName(workExampleIndices.getName());
								exampleEconomics.setId("");
								exampleEconomicsService.save(exampleEconomics);
							}else if("5".equals(exampleIndices.getType())){
								//主要工程量指标
								ExampleProject exampleProject = new ExampleProject();
								exampleProject.setIndexId(id);
								exampleProject.setExampleId(exampleId);
								exampleProject.setExampleindicesId(workExampleIndices.getId());
								exampleProject.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
								exampleProject.setDigits(workExampleIndices.getDecimalCount());
								exampleProject.setName(workExampleIndices.getName());
								exampleProject.setId("");
								exampleProjectService.save(exampleProject);
							}else if("6".equals(exampleIndices.getType())){
								//主要工料价格及消耗量指标
								ExampleExpend exampleExpend = new ExampleExpend();
								exampleExpend.setIndexId(id);
								exampleExpend.setExampleId(exampleId);
								exampleExpend.setExampleindicesId(workExampleIndices.getId());
								exampleExpend.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
								exampleExpend.setDigits(workExampleIndices.getDecimalCount());
								exampleExpend.setName(workExampleIndices.getName());
								exampleExpend.setId("");
								exampleExpendService.save(exampleExpend);
							}
						}
					}
				}catch (Exception e){
					logger.info("Exception e:"+e);
				}
			}
		}
		return ajaxJson;
	}

	/**
	 * 删除指标字典
	 */
	//@RequiresPermissions("workexample:workExampleIndices:del")
	@RequestMapping(value = "delete")
	public String delete(WorkExampleIndices workExampleIndices,String status, RedirectAttributes redirectAttributes) {
		workExampleIndices.setIsDisable(status);
		workExampleIndicesService.updateStatus(workExampleIndices);
		if (status.equals("1")){
			addMessage(redirectAttributes, "禁用项目指标成功");
		}else{
			addMessage(redirectAttributes, "启用项目指标成功");
		}

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

	/**
	 * 导入Excel数据

	 */
	//@RequiresPermissions("workexample:workExampleIndices: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<WorkExampleIndices> list = ei.getDataList(WorkExampleIndices.class);
			for (WorkExampleIndices workExampleIndices : list){
				try{
					workExampleIndicesService.save(workExampleIndices);
					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()+"/workexample/workExampleIndices/?repage";
    }
	
	/**
	 * 下载导入指标字典数据模板
	 */
	//@RequiresPermissions("workexample:workExampleIndices:import")
    @RequestMapping(value = "import/template")
    public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "指标字典数据导入模板.xlsx";
    		List<WorkExampleIndices> list = Lists.newArrayList(); 
    		new ExportExcel("指标字典数据", WorkExampleIndices.class, 1).setDataList(list).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入模板下载失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/workexample/workExampleIndices/?repage";
    }

	/**
	 * 获取机构JSON数据。
	 *
	 * @param extId    排除的ID
	 * @param type     类型（1：公司；2：部门/小组/其它：3：用户）
	 * @param response
	 * @return
	 */
	@RequiresPermissions("user")
	@ResponseBody
	@RequestMapping(value = "treeDataExample")
	public List<Map<String, Object>> treeDataExample(@RequestParam(required = false) String workExampleId, @RequestParam(required = false) String extId, @RequestParam(required = false) String type, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
		List<Map<String, Object>> mapList = new ArrayList<>();
		List<WorkExampleIndices> list = new ArrayList<>();
		WorkExampleIndices workExampleIndices = new WorkExampleIndices();
		workExampleIndices.setParent(new WorkExampleIndices("0"));
		workExampleIndices.setParentIds("0");
		workExampleIndices.setName("工程名称");
		workExampleIndices.setType("0");
		workExampleIndices.setId("-1");
		list.add(workExampleIndices);
		WorkExampleIndices exampleIndices = new WorkExampleIndices();
		exampleIndices.setParent(new WorkExampleIndices("-1"));
		exampleIndices.setParentIds("0,");
		exampleIndices.setName("工程概况");
		exampleIndices.setType("0");
		exampleIndices.setId("");
		list.add(exampleIndices);
		if(StringUtils.isNotBlank(workExampleId)) {
			WorkExampleIndices workExampleIndice1 = new WorkExampleIndices();
			workExampleIndice1.setCompanyId(UserUtils.getSelectCompany().getId());
			workExampleIndice1.setWorkExample(new WorkExample(workExampleId));
			workExampleIndice1.setIsDisable("0");
			List<WorkExampleIndices> workExampleIndicesList = workExampleIndicesService.findListInfo(workExampleIndice1);
			if (workExampleIndicesList != null && workExampleIndicesList.size() != 0) {
				list.addAll(workExampleIndicesList);
			}
		}
		for (int i = 0; i < list.size(); i++) {
			WorkExampleIndices e = list.get(i);
			if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
					) {
				Map<String, Object> map = Maps.newHashMap();
				map.put("id", e.getId());
				map.put("pId", e.getParent().getId().equals("0")?"-1":e.getParent().getId());
				map.put("pIds", e.getParentIds().replaceFirst("0,","0,-1,"));
				map.put("name", e.getName());
				map.put("type",e.getType());
				if (e.getType() != null &&(Integer.parseInt(e.getType()) == 2 || Integer.parseInt(e.getType()) == 3 )){
					map.put("isParent", true);
				} else {
					map.put("isParent", false);
				}
				mapList.add(map);
			}
		}
		return mapList;
	}

	/**
	 * 获取机构JSON数据。
	 *
	 * @param extId    排除的ID
	 * @param type     类型（1：公司；2：部门/小组/其它：3：用户）
	 * @param response
	 * @return
	 */
	@RequiresPermissions("user")
	@ResponseBody
	@RequestMapping(value = "treeDataExampleInfo")
	public List<Map<String, Object>> treeDataExampleInfo(@RequestParam(required = false) String extId, @RequestParam(required = false) String type, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
		List<Map<String, Object>> mapList = new ArrayList<>();
		WorkExampleIndices workExampleIndice1 = new WorkExampleIndices();
		workExampleIndice1.setCompanyId(UserUtils.getSelectCompany().getId());
		workExampleIndice1.setView("view");
		workExampleIndice1.setIsDisable("0");
		List<WorkExampleIndices> list = workExampleIndicesService.findList(workExampleIndice1);
		for (int i = 0; i < list.size(); i++) {
			WorkExampleIndices e = list.get(i);
			if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
					) {
				Map<String, Object> map = Maps.newHashMap();
				map.put("id", e.getId());
				map.put("pId", e.getParent().getId());
				map.put("pIds", e.getParentIds());
				map.put("name", e.getName());
				map.put("type",e.getType());
				if (e.getType() != null &&(Integer.parseInt(e.getType()) == 2 || Integer.parseInt(e.getType()) == 3 )|| Integer.parseInt(e.getType()) == 0){
					map.put("isParent", true);
				} else {
					map.put("isParent", false);
				}
				mapList.add(map);
			}
		}
		return mapList;
	}

	/**
	 * 获取机构JSON数据。
	 *
	 * @param extId    排除的ID
	 * @param type     类型（1：公司；2：部门/小组/其它：3：用户）
	 * @param response
	 * @return
	 */
	@RequiresPermissions("user")
	@ResponseBody
	@RequestMapping(value = "treeDataExampleSelect")
	public List<Map<String, Object>> treeDataExampleSelect(@RequestParam(required = false) String extId, @RequestParam(required = false) String type, @RequestParam(required = false) Boolean isAll, HttpServletResponse response) {
		List<Map<String, Object>> mapList = new ArrayList<>();
		List<WorkExampleIndices> list = new ArrayList<>();
		WorkExampleIndices workExampleIndices = new WorkExampleIndices();
		workExampleIndices.setParent(new WorkExampleIndices("0"));
		workExampleIndices.setParentIds("0");
		workExampleIndices.setName("工程名称");
		workExampleIndices.setType("0");
		workExampleIndices.setId("-1");
		list.add(workExampleIndices);
		WorkExampleIndices exampleIndices = new WorkExampleIndices();
		exampleIndices.setParent(new WorkExampleIndices("-1"));
		exampleIndices.setParentIds("0,");
		exampleIndices.setName("工程概况");
		exampleIndices.setType("0");
		exampleIndices.setId("");
		list.add(exampleIndices);
		WorkExampleIndices workExampleIndice1 = new WorkExampleIndices();
		workExampleIndice1.setCompanyId(UserUtils.getSelectCompany().getId());
		workExampleIndice1.setView("view");
		workExampleIndice1.setIsDisable("0");
		list.addAll(workExampleIndicesService.findList(workExampleIndice1));
		for (int i = 0; i < list.size(); i++) {
			WorkExampleIndices e = list.get(i);
			if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf("," + extId + ",") == -1))
					) {
				Map<String, Object> map = Maps.newHashMap();
				map.put("id", e.getId());
				map.put("pId", e.getParent().getId().equals("0")?"-1":e.getParent().getId());
				map.put("name", e.getName());
				map.put("pIds", e.getParentIds().replaceFirst("0,","0,-1,"));
				map.put("type",e.getType());
				if (e.getType() != null &&(Integer.parseInt(e.getType()) == 2 || Integer.parseInt(e.getType()) == 3 )){
					map.put("isParent", true);
				} else {
					map.put("isParent", false);
				}
				mapList.add(map);
			}
		}
		return mapList;
	}

	@RequestMapping(value = "gridSelectIndices")
	public String gridSelectIndices(WorkExampleIndices workExampleIndices,String url,String indexId, HttpServletRequest request, HttpServletResponse response, Model model){
		List<WorkExampleIndices> list =new ArrayList<>();
		if(StringUtils.isNotBlank(indexId)){
			workExampleIndices.setId(indexId);
		}
		Page<WorkExampleIndices> page = workExampleIndicesService.findPageByParentId(new Page<WorkExampleIndices>(request, response),  workExampleIndices);
		model.addAttribute("workExampleIndices", workExampleIndices);
		model.addAttribute("url", url);
		model.addAttribute("indexId", indexId);
		model.addAttribute("page", page);
		return  "modules/sys/gridSelectSingle";
	}

	@ResponseBody
	@RequestMapping(value = "saveIndices")
	public AjaxJson saveIndices(String indexId,String exampleId ,String ids,HttpServletRequest request, HttpServletResponse response, Model model) {
		String[] idArr = ids.split(",");
		//筛选
		AjaxJson j = new AjaxJson();
		WorkExampleIndices exampleIndices = workExampleIndicesService.get(indexId);
		List list = Lists.newArrayList();
		for (String id:idArr){
			if(StringUtils.isNotBlank(id)){
				if("1".equals(exampleIndices.getType())){
					//单项工程造价指标
					WorkExampleIndices workExampleIndices = workExampleIndicesService.get(id);
					ExampleSingle exampleSingle = new ExampleSingle();
					exampleSingle.setIndexId(indexId);
					exampleSingle.setExampleId(exampleId);
					exampleSingle.setExampleIndicesId(id);
					exampleSingle.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
					exampleSingle.setDigits(workExampleIndices.getDecimalCount());
					exampleSingle.setName(workExampleIndices.getName());
					list.add(exampleSingle);
				}else if("4".equals(exampleIndices.getType())){
					//经济指标
					WorkExampleIndices workExampleIndices = workExampleIndicesService.get(id);
					ExampleEconomics exampleEconomics = new ExampleEconomics();
					exampleEconomics.setIndexId(indexId);
					exampleEconomics.setExampleId(exampleId);
					exampleEconomics.setExampleindicesId(id);
					exampleEconomics.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
					exampleEconomics.setDigits(workExampleIndices.getDecimalCount());
					exampleEconomics.setName(workExampleIndices.getName());
					list.add(exampleEconomics);
				}else if("5".equals(exampleIndices.getType())){
					//主要工程量指标
					WorkExampleIndices workExampleIndices = workExampleIndicesService.get(id);
					ExampleProject exampleProject = new ExampleProject();
					exampleProject.setIndexId(indexId);
					exampleProject.setExampleId(exampleId);
					exampleProject.setExampleindicesId(id);
					exampleProject.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
					exampleProject.setDigits(workExampleIndices.getDecimalCount());
					exampleProject.setName(workExampleIndices.getName());
					list.add(exampleProject);
				}else if("6".equals(exampleIndices.getType())){
					//主要工料价格及消耗量指标
					WorkExampleIndices workExampleIndices = workExampleIndicesService.get(id);
					ExampleExpend exampleExpend = new ExampleExpend();
					exampleExpend.setIndexId(indexId);
					exampleExpend.setExampleId(exampleId);
					exampleExpend.setExampleindicesId(id);
					exampleExpend.setUnit(DictUtils.getMainDictLabel(workExampleIndices.getItemUnit(),"unit_type",""));//unit_type     getMainDictList
					exampleExpend.setDigits(workExampleIndices.getDecimalCount());
					exampleExpend.setName(workExampleIndices.getName());
					list.add(exampleExpend);
				}
			}
		}
		j.put("list", list);
		j.put("indexId",indexId);
		return j;
	}
}