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

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActTaskService;
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.entity.Office;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.utils.ErrorCode;
import com.jeeplus.modules.workexample.entity.WorkExampleIndices;
import com.jeeplus.modules.workexample.service.WorkExampleIndicesService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.history.HistoricProcessInstance;
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 com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.workexample.entity.WorkExample;
import com.jeeplus.modules.workexample.service.WorkExampleService;

/**
 * 案例Controller
 * @author ssrh
 * @version 2018-08-27
 */
@Controller
@RequestMapping(value = "${adminPath}/workexample/workExample")
public class WorkExampleController extends BaseController {

	@Autowired
	private WorkExampleService workExampleService;
	@Autowired
	private HistoryService historyService;
	@Autowired
	private WorkExampleIndicesService workExampleIndicesService;

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private ActTaskService actTaskService;
	@Autowired
	private ExampleSingleService exampleSingleService;
	@Autowired
	private ExampleProjectService exampleProjectService;
	@Autowired
	private ExampleExpendService exampleExpendService;
	@Autowired
	private ExampleEconomicsService exampleEconomicsService;

	@ModelAttribute
	public WorkExample get(@RequestParam(required=false) String id) {
		WorkExample entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = workExampleService.get(id);
		}
		if (entity == null){
			entity = new WorkExample();
		}
		return entity;
	}
	
	/**
	 * 案例列表页面
	 */
	@RequiresPermissions("workexample:workExample:list")
	@RequestMapping(value = {"list", ""})
	public String list(WorkExample workExample, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<WorkExample> page = workExampleService.findPage(new Page<WorkExample>(request, response), workExample); 
		model.addAttribute("page", page);
		return "modules/workexample/workExampleList";
	}
	/**
	 * 案例列表页面
	 */
	@RequestMapping(value = {"listView"})
	public String listView(WorkExample workExample, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<WorkExample> page = workExampleService.findPage(new Page<WorkExample>(request, response), workExample);
		model.addAttribute("page", page);
		return "modules/workexample/workExampleListView";
	}

	/**
	 * 查看，增加，编辑案例表单页面
	 */
	//@RequiresPermissions(value={"workexample:workExample:view","workexample:workExample:add","workexample:workExample:edit"},logical=Logical.OR)
	@RequestMapping(value = "form")
	public String form(WorkExample workExample, Model model) {
		Office office = UserUtils.getSelectOffice();
		String tabId = request.getParameter("tabId");
		if("1".equals(tabId)){
			model.addAttribute("workExample", workExample);
            model.addAttribute("sign", "view");
			return "modules/workexample/workExampleIndex";
		}else if("3".equals(tabId)){
			ProcessInstance processInstance = actTaskService.getProcIns(workExample.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);
				workExample.setAct(act);
				//view = "workExampleModify";
				model.addAttribute("workExample", workExample);
                model.addAttribute("sign", "modify");
				return "modules/workexample/workExampleIndex";
			}
		}
		// 环节编号
		String taskDefKey = workExample.getAct().getTaskDefKey();
		if (StringUtils.isNotBlank(taskDefKey) && ("alshr".equals(taskDefKey))){
			model.addAttribute("workExample", workExample);
            model.addAttribute("sign", "audit");
			return "modules/workexample/workExampleIndex";
		}
        model.addAttribute("workExample", workExample);
        model.addAttribute("sign", "form");
		return "modules/workexample/workExampleIndex";
	}
    @RequestMapping(value = "view")
    public String view(WorkExample workExample, Model model) {
        model.addAttribute("workExample", workExample);
        return "modules/workexample/workExampleView";
    }

    @RequestMapping(value = "forms")
    public String forms(WorkExample workExample, Model model) {
        model.addAttribute("workExample", workExample);
        return "modules/workexample/workExampleForm";
    }

    @RequestMapping(value = "audit")
    public String audit(WorkExample workExample, Model model) {
		workExample.setHome("home");
		workExample.setAct(getByAct(workExample.getProcessInstanceId()));
        model.addAttribute("workExample", workExample);
        return "modules/workexample/workExampleAudit";
    }
    @RequestMapping(value = "modify")
    public String modify(WorkExample workExample, Model model) {
		workExample.setAct(getByAct(workExample.getProcessInstanceId()));
        model.addAttribute("workExample", workExample);
        return "modules/workexample/workExampleModify";
    }
	public Act getByAct(String processInstanceId){
		Act act = new Act();
		HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
		ProcessInstance processInstance = actTaskService.getProcIns(processInstanceId);
		if (processInstance!=null) {
			List<Task> taskList = actTaskService.getCurrentTaskList(processInstance);
			if(taskList!=null && taskList.size()>1){
				for (Task taskInfok:taskList) {
					if (taskInfok.getAssignee().equals(UserUtils.getUser().getId())) {
						act.setTaskId(taskInfok.getId());
						act.setTaskName(taskInfok.getName());
						act.setTaskDefKey(taskInfok.getTaskDefinitionKey());
						act.setProcDefId(taskInfok.getProcessDefinitionId());
						act.setProcInsId(taskInfok.getProcessInstanceId());
						act.setTask(taskInfok);
					}
				}
			}else {
				Task task = actTaskService.getCurrentTaskInfo(processInstance);
				act.setTaskId(task.getId());
				act.setTaskName(task.getName());
				act.setTaskDefKey(task.getTaskDefinitionKey());
				act.setProcDefId(task.getProcessDefinitionId());
				act.setProcInsId(task.getProcessInstanceId());
				act.setTask(task);
			}
		}
		return  act;
	}
	/**
	 * 暂存
	 */
	@RequestMapping(value = "store")
	public String store(WorkExample workExample,
						Model model,
						RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, workExample)){
			return form(workExample, model);
		}
		User user = workExample.getCreateBy();
		String submitter = "";
		if(user != null){
			submitter = user.getId();
		}
		String sta = workExample.getStatus();
		if(!UserUtils.getUser().getId().equals(submitter) && !Strings.isNullOrEmpty(submitter) && sta != null){
			addMessage(redirectAttributes, "您不是申请人，无法修改");
			return "redirect:"+Global.getAdminPath()+"/workexample/workExample/?repage";
		}
		workExample.setStatus("1"); //暂存状态
		workExample.setCompanyId(UserUtils.getSelectCompany().getId());
		workExample.setOfficeId(UserUtils.getSelectOffice().getId());
		if (StringUtils.isNotBlank(workExample.getProcessInstanceId()) && workExample.getProcessInstanceId().equals("NULL")){
			workExample.setProcessInstanceId("");
		}
		if(!workExample.getIsNewRecord()){//编辑表单保存
			WorkExample t = workExampleService.get(workExample.getId());//从数据库取出记录的值
			MyBeanUtils.copyBeanNotNull2Bean(workExample, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
			workExampleService.save(t);//保存
		}else{//新增表单保存
			workExampleService.save(workExample);//保存
		}
		addMessage(redirectAttributes, "保存案例成功");
		return "redirect:"+Global.getAdminPath()+"/workexample/workExample/?repage";
	}

	/**
	 * 保存案例
	 */
	/*@RequiresPermissions(value={"workexample:workExample:add","workexample:workExample:edit"},logical=Logical.OR)
	@RequestMapping(value = "save")
	public String save(WorkExample workExample, Model model, RedirectAttributes redirectAttributes) throws Exception{
		if (!beanValidator(model, workExample)){
			return form(workExample, model);
		}
		User user = workExample.getCreateBy();
		String sta = workExample.getStatus();
		if(user!=null && !UserUtils.getUser().getId().equals(user.getId()) && StringUtils.isNotBlank(user.getId())){
			addMessage(redirectAttributes, "您不是申请人，无法修改");
			return "redirect:"+Global.getAdminPath()+"/workexample/workExample/?repage";
		}
		//状态设置为审核中
		workExample.setStatus("2");
		String processInstanceId ="";
		if (user!=null && StringUtils.isNotBlank(user.getId()) && StringUtils.isNotBlank(sta) && "3".equals(sta)){
			processInstanceId = workExampleService.get(workExample.getId()).getProcessInstanceId();
		}
		try {
			Map<String, Object> variables = Maps.newHashMap();
			workExample.setCompanyId(UserUtils.getSelectCompany().getId());
			workExample.setOfficeId(UserUtils.getSelectOffice().getId());
			String str = workExampleService.save(workExample, variables,processInstanceId);
			if (StringUtils.isNotBlank(str)){
				addMessage(redirectAttributes, "案例申请提交失败:"+str);
			}else {
				addMessage(redirectAttributes, "案例申请已经提交");
			}

		} catch (Exception e) {
			addMessage(redirectAttributes, "案例申请提交失败!");
			addMessage(redirectAttributes, "系统内部错误");
		}
		logger.info("redirect:"+ adminPath +"/workexample/workExample/list?repage"+"-------");
		//return "modules/workexample/workExampleList";
		return "redirect:"+ adminPath +"/workexample/workExample/list?repage";

		//redirect:/a/workexample/workExample/list?repage-------
	}*/
	@ResponseBody
	@RequestMapping(value = "save")
	@RequiresPermissions(value={"workexample:workExample:add","workexample:workExample:edit"},logical=Logical.OR)
	public AjaxJson save(WorkExample workExample,HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		AjaxJson j = new AjaxJson();
		//状态设置为审核中
		workExample.setStatus("2");
		String processInstanceId ="";
		User user = workExample.getCreateBy();
		String sta = workExample.getStatus();
		String str = null;
		if (user!=null && StringUtils.isNotBlank(user.getId()) && StringUtils.isNotBlank(sta) && "3".equals(sta)){
			processInstanceId = workExampleService.get(workExample.getId()).getProcessInstanceId();
		}
		try {
			Map<String, Object> variables = Maps.newHashMap();
			workExample.setCompanyId(UserUtils.getSelectCompany().getId());
			workExample.setOfficeId(UserUtils.getSelectOffice().getId());
			str = workExampleService.save(workExample, variables,processInstanceId);
			if (StringUtils.isNotBlank(str)){
				j.setMsg("案例申请提交失败"+str);
				j.put("type",false);
			}else {
				j.setMsg("案例申请已经提交");
				j.put("type",true);
				j.setSuccess(true);
			}
		} catch (Exception e) {
			logger.error("送审失败：", e);
			j.setSuccess(false);
			j.setErrorCode(ErrorCode.code_2004);
			j.setMsg("案例申请提交失败"+str);
			j.put("type",false);
		}
		return j;
	}

	@ResponseBody
	@RequestMapping(value = "saveAudit")
	@RequiresPermissions(value={"workexample:workExample:add","workexample:workExample:edit"},logical=Logical.OR)
	public AjaxJson saveAudit (WorkExample workExample,HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		AjaxJson j = new AjaxJson();
		String str = null;
		try {
			List<User> users = UserUtils.getByProssType(workExample.getProcessInstanceId(),1);
			String flag = workExample.getAct().getFlag();
			if ("yes".equals(flag) && (users==null || users.size()==0)){
				addMessage(redirectAttributes, "审批失败,审批人为空,请联系管理员！");
				j.setMsg("审批失败,审批人为空,请联系管理员！");
				j.put("type",false);
			}else {
				str = workExampleService.auditSave(workExample,users);
				addMessage(redirectAttributes, str);
				j.setMsg(str);
				j.put("type",true);
				j.setSuccess(true);
			}
		} catch (Exception e) {
			logger.error("审批失败：", e);
			j.setSuccess(false);
			j.setErrorCode(ErrorCode.code_2004);
			j.setMsg("审批失败"+str);
			j.put("type",false);
		}
		return j;
	}

	/*@RequestMapping(value = "saveAudit")
	public String saveAudit(WorkExample workExample, Model model,
							RedirectAttributes redirectAttributes) {
		try {
			List<User> users = UserUtils.getByProssType(workExample.getProcessInstanceId(),1);
			String flag = workExample.getAct().getFlag();
			if ("yes".equals(flag) && (users==null || users.size()==0)){
				addMessage(redirectAttributes, "审批失败,审批人为空,请联系管理员！");
			}else {
				String str = workExampleService.auditSave(workExample,users);
				addMessage(redirectAttributes, str);
			}
		}catch (Exception e){
			addMessage(redirectAttributes, "审批失败");
		}

		if (StringUtils.isNotBlank(workExample.getHome()) && "home".equals(workExample.getHome())){
			return "redirect:" + Global.getAdminPath() + "/home/?repage";
		}else {
			return "redirect:"+Global.getAdminPath()+"/workexample/workExample/?repage";
		}
	}*/
	@ResponseBody
	@RequestMapping(value = "saveAudits")
	@RequiresPermissions(value={"workexample:workExample:add","workexample:workExample:edit"},logical=Logical.OR)
	public AjaxJson saveAudits (WorkExample workExample,HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		AjaxJson j = new AjaxJson();
		String str = null;
		try {
			List<User> users = UserUtils.getByProssType(workExample.getProcessInstanceId(),1);
			String flag = workExample.getAct().getFlag();
			if ("yes".equals(flag) && (users==null || users.size()==0)){
				addMessage(redirectAttributes, "审批失败,审批人为空,请联系管理员！");
				j.setMsg("审批失败,审批人为空,请联系管理员！");
				j.put("type",false);
			}else {
				str = workExampleService.auditSaves(workExample,users);
				addMessage(redirectAttributes, str);
				j.setMsg(str);
				j.put("type",true);
				j.setSuccess(true);
			}
		} catch (Exception e) {
			logger.error("审批失败：", e);
			j.setSuccess(false);
			j.setErrorCode(ErrorCode.code_2004);
			j.setMsg("审批失败"+str);
			j.put("type",false);
		}
		return j;
	}
	/*@RequestMapping(value = "saveAudits")
	public String saveAudits(WorkExample workExample, Model model,
							RedirectAttributes redirectAttributes) {
		try {
			List<User> users = UserUtils.getByProssType(workExample.getProcessInstanceId(),1);
			String flag = workExample.getAct().getFlag();
			if ("yes".equals(flag) && (users==null || users.size()==0)){
				addMessage(redirectAttributes, "审批失败,审批人为空,请联系管理员！");
			}else {
				String str = workExampleService.auditSaves(workExample,users);
				addMessage(redirectAttributes, str);
			}
		}catch (Exception e){
			addMessage(redirectAttributes, "审批失败");
		}

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


	

	/**
	 * 强制撤销
	 */
	@RequestMapping("cancelInvalidate")
	public String cancelInvalidate(WorkExample workExample,RedirectAttributes redirectAttributes){
		workExampleService.cancelInvalidate(workExample);
		return "redirect:"+Global.getAdminPath()+"/workexample/workExample/?repage";
	}

	@RequestMapping(value = "getProcessOne")
	public String getProcessOne(WorkExample workExample,Model model) {
		model.addAttribute("processInstanceId", workExample.getProcessInstanceId());
		return "modules/workexample/workTrack";
	}
	@ResponseBody
	@RequestMapping("checkSame")
	public AjaxJson checkSame(WorkExample workExample){
		AjaxJson ajaxJson = new AjaxJson();
		//String id = null;
		logger.info(workExample.toString());
		if(StringUtils.isBlank(workExample.getName())){
			ajaxJson.getBody().put("data",workExample);
			return ajaxJson;
		}else{
			try {
				if (!workExample.getIsNewRecord()) {//编辑表单保存
					WorkExample t = workExampleService.get(workExample.getId());//从数据库取出记录的值
					MyBeanUtils.copyBeanNotNull2Bean(workExample, t);//将编辑表单中的非NULL值覆盖数据库记录中的值
					workExampleService.save(t);//保存
					ajaxJson.getBody().put("data",t);
				} else {//新增表单保存
					workExample.setStatus("1");
					workExample.setCompanyId(UserUtils.getSelectCompany().getId());
					workExample.setOfficeId(UserUtils.getSelectOffice().getId());
					//caseInfo.setUserids(getPeopleMaster());
					workExampleService.save(workExample);//保存
					ajaxJson.getBody().put("data",workExample);
				}
			}catch (Exception e) {
				ajaxJson.getBody().put("data",workExample);
				logger.info(e.getMessage());
			}
		}
		return ajaxJson;
	}

	@ResponseBody
	@RequestMapping(value = "selectSingle")
	public AjaxJson selectSingle(String indexId,String eId ,HttpServletRequest request, HttpServletResponse response, Model model) {
		AjaxJson j = new AjaxJson();
		List<ExampleSingle> list = Lists.newArrayList();
		if(StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(eId)){
			ExampleSingle exampleSingle = new ExampleSingle();
			exampleSingle.setExampleId(eId);
			exampleSingle.setIndexId(indexId);
			list = exampleSingleService.findList(exampleSingle);
		}
		j.put("list", list);
		return j;
	}

	@ResponseBody
	@RequestMapping(value = "selectProject")
	public AjaxJson selectProject(String indexId,String eId ,HttpServletRequest request, HttpServletResponse response, Model model) {
		AjaxJson j = new AjaxJson();
		List<ExampleProject> list = Lists.newArrayList();
		if(StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(eId)){
			ExampleProject exampleProject = new ExampleProject();
			exampleProject.setExampleId(eId);
			exampleProject.setIndexId(indexId);
			list = exampleProjectService.findList(exampleProject);
		}
		j.put("list", list);
		return j;
	}
	@ResponseBody
	@RequestMapping(value = "selectExpend")
	public AjaxJson selectExpend(String indexId,String eId ,HttpServletRequest request, HttpServletResponse response, Model model) {
		AjaxJson j = new AjaxJson();
		List<ExampleExpend> list = Lists.newArrayList();
		if(StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(eId)){
			ExampleExpend exampleExpend = new ExampleExpend();
			exampleExpend.setExampleId(eId);
			exampleExpend.setIndexId(indexId);
			list = exampleExpendService.findList(exampleExpend);
		}
		j.put("list", list);
		return j;
	}
	@ResponseBody
	@RequestMapping(value = "selectEconomics")
	public AjaxJson selectEconomics(String indexId,String eId ,HttpServletRequest request, HttpServletResponse response, Model model) {
		AjaxJson j = new AjaxJson();
		List<ExampleEconomics> list = Lists.newArrayList();
		if(StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(eId)){
			ExampleEconomics exampleEconomics = new ExampleEconomics();
			exampleEconomics.setExampleId(eId);
			exampleEconomics.setIndexId(indexId);
			list = exampleEconomicsService.findList(exampleEconomics);
		}
		j.put("list", list);
		return j;
	}
	@ResponseBody
	@RequestMapping(value = "deleteIndex")
	public AjaxJson deleteIndex(String indexId,String exampleId ,String type,HttpServletRequest request, HttpServletResponse response, Model model) {
		AjaxJson j = new AjaxJson();
		try {
			if ("1".equals(type)) {
				if (StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(exampleId)) {
					exampleSingleService.delteByIndexId(exampleId,indexId);
				}
			} else if ("4".equals(type)) {
				if (StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(exampleId)) {
					exampleEconomicsService.delteByIndexId(exampleId,indexId);
				}
			} else if ("5".equals(type)) {
				if (StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(exampleId)) {
					exampleProjectService.delteByIndexId(exampleId,indexId);
				}
			} else if ("6".equals(type)) {
				if (StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(exampleId)) {
					exampleExpendService.delteByIndexId(exampleId,indexId);
				}
			}
			//删除树
			if (StringUtils.isNotBlank(indexId) && StringUtils.isNotBlank(exampleId)) {
				workExampleIndicesService.deleteExampleIndices(exampleId, indexId);
			}
			j.put("result",true);
			return j;
		}catch (Exception e){
			j.put("result",false);
			return j;
		}
	}
}