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

import com.google.common.collect.Maps;
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.common.utils.MyBeanUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.isignature.service.ISignatureDocumentService;
import com.jeeplus.modules.projectcontentinfo.dao.ProjectContentChangeDao;
import com.jeeplus.modules.projectcontentinfo.dao.ProjectcontentinfoDao;
import com.jeeplus.modules.projectcontentinfo.entity.*;
import com.jeeplus.modules.projectcontroltable.dao.ProjectControlTableDao;
import com.jeeplus.modules.projectcontroltable.entity.ProjectControlTable;
import com.jeeplus.modules.projectrecord.entity.ProjectRecords;
import com.jeeplus.modules.projectrecord.service.ProjectRecordsService;
import com.jeeplus.modules.projectreportnum.service.ProjectReportNumService;
import com.jeeplus.modules.sys.dao.WorkattachmentDao;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.entity.Workattachment;
import com.jeeplus.modules.sys.utils.DictUtils;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.workactivity.service.WorkActivityProcessService;
import com.jeeplus.modules.workcontent.entity.WorkContentType;
import com.jeeplus.modules.workcontent.service.WorkContentDetailBaseService;
import com.jeeplus.modules.workcontent.common.WorkContentDetailFactory;
import com.jeeplus.modules.workcontent.service.WorkContentTypeService;
import com.jeeplus.modules.workprojectnotify.entity.WorkProjectNotify;
import com.jeeplus.modules.workprojectnotify.service.WorkProjectNotifyService;
import com.jeeplus.modules.workreview.entity.WorkReviewAudit;
import com.jeeplus.modules.workreview.entity.WorkReviewStandard;
import com.jeeplus.modules.workreview.service.WorkReviewStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;

/**
 * 工作内容管理Service
 * @author yangfan
 * @version 2018-06-04
 */
@Service
@Transactional(readOnly = true)
public class ProjectcontentinfoService extends CrudService<ProjectcontentinfoDao, Projectcontentinfo> {
	@Autowired
	private ProjectBasedDataService projectBasedDataService;
	@Autowired
	private ProjectContentDataService projectContentDataService;
	@Autowired
	private ProjectReportDataService projectReportDataService;
	@Autowired
	private ProjectReportChangeService projectReportChangeService;
	@Autowired
	private WorkattachmentDao workattachmentDao;
	@Autowired
	private ProjectContentChangeDao projectContentChangeDao;
	@Autowired
	private WorkContentTypeService contentTypeService;
	@Autowired
	private ProjectRecordsService projectRecordsService;
	@Autowired
	private WorkProjectNotifyService workProjectNotifyService;
	@Autowired
	private ProjectControlTableDao controlTableDao;
	@Autowired
	private WorkActivityProcessService workActivityProcessService;
	@Autowired
	private WorkReviewStandardService workReviewStandardService;
	@Autowired
	private ProjectReportRecordService projectReportRecordService;
	@Autowired
	private ISignatureDocumentService signatureDocumentService;
	@Autowired
	private ProjectReportNumService projectReportNumService;

	public Projectcontentinfo get(String id) {
		return super.get(id);
	}
	public boolean getOrChange(String id) {
		Projectcontentinfo projectcontentinfo = super.get(id);
		if (projectcontentinfo==null || StringUtils.isBlank(projectcontentinfo.getId())){
			return false;
		}else {
			return true;
		}
	}
	public Projectcontentinfo getChange(String id) {
		return projectContentChangeDao.get(id);
	}
	public Projectcontentinfo getByInfoId(String infoId) {
		return dao.getByInfoId(infoId);
	}
	public List<Projectcontentinfo> getByChangeInfoId(String infoId) {
		return projectContentChangeDao.getByInfoId(infoId);
	}
	public Projectcontentinfo findByType(Projectcontentinfo projectcontentinfo) {
		return dao.findByType(projectcontentinfo);
	}
	public List<Projectcontentinfo> findListByProject(Projectcontentinfo projectcontentinfo) {
		return dao.findListByProject(projectcontentinfo);
	}
	public List<Projectcontentinfo> findByParentIds(Projectcontentinfo projectcontentinfo) {
		//详情页面
		ProjectContentData projectContentData = projectContentDataService.get(projectcontentinfo.getLinkId());
		Projectcontentinfo contentinfo = getByInfoId(projectContentData.getId());

		return dao.findByParentIds(contentinfo.getProject().getId(),contentinfo.getId());
	}
	public Projectcontentinfo findByBasedInfo(Projectcontentinfo projectcontentinfo) {
		//详情页面
		ProjectBasedData projectBasedData = projectBasedDataService.get(projectcontentinfo.getLinkId());
		Projectcontentinfo contentinfo = getByInfoId(projectBasedData.getId());
		return contentinfo;
	}

	public List<Projectcontentinfo> findList(Projectcontentinfo projectcontentinfo) {
		List<Projectcontentinfo> projectcontentinfos = super.findList(projectcontentinfo);
		return projectcontentinfos;
	}
	public List<Projectcontentinfo> findListByReport(Projectcontentinfo projectcontentinfo) {
		List<Projectcontentinfo> projectcontentinfos = projectContentChangeDao.findList(projectcontentinfo);
		return projectcontentinfos;
	}

	public Page<Projectcontentinfo> findPage(Page<Projectcontentinfo> page, Projectcontentinfo projectcontentinfo) {
		//设置数据权限
		projectcontentinfo.setPage(page);
		page.setList(findList(projectcontentinfo));
		return super.findPage(page, projectcontentinfo);
	}

	@Transactional(readOnly = false)
	public void save(Projectcontentinfo projectcontentinfo) {
		super.save(projectcontentinfo);
	}
	@Transactional(readOnly = false)
	public void insertChange(Projectcontentinfo projectcontentinfo) {
		projectcontentinfo.preInsert();
		projectContentChangeDao.insert(projectcontentinfo);
	}
	@Transactional(readOnly = false)
	public void deleteChange(Projectcontentinfo projectcontentinfo) {
		projectContentChangeDao.deleteChange(projectcontentinfo);
	}
	@Transactional(readOnly = false)
	public String saveData(Projectcontentinfo projectcontentinfo,int type) throws Exception {
		List<ProjectControlTable> projectControlTableList = null;
		List<ProjectBasedData> projectBasedDataList = null;
		List<ProjectContentData> projectContentDataList = null;
		String dictName ="";
		String count = "0";
		int sort = 0;
		String name = "";
		String dataName = "";
		String infoId = "";
		String dictType = projectcontentinfo.getDictType();
		Projectcontentinfo s = new Projectcontentinfo();
		s.setParentIds("0,");
		s.setProject(projectcontentinfo.getProject());
		Projectcontentinfo contentinfo = dao.findListByProject(s).get(0);
		String parentIds = projectcontentinfo.getParentIds();
		String parentId = projectcontentinfo.getParentId();
		Projectcontentinfo parent = contentinfo;
		List<Workattachment> attachmentList = projectcontentinfo.getWorkAttachments();
		boolean save = false;
		//判断提交的是依据性资料、工作内容、工作报告
		if (projectcontentinfo.getProjectBasedData()!=null){
			ProjectBasedData basedData = projectcontentinfo.getProjectBasedData();
			basedData.setCompanyId(contentinfo.getCompanyId());
			basedData.setOfficeId(contentinfo.getOfficeId());
			basedData.setProject(contentinfo.getProject());
			if (StringUtils.isBlank(basedData.getNumber())) {
				//生成依据性资料编号
				String number = projectBasedDataService.getNumber(contentinfo.getProject());
				basedData.setNumber(number);
			}
			dictName = DictUtils.getDictLabel(basedData.getType(),"project_document_type","");
			//保存依据性资料
			projectBasedDataService.save(basedData);
			count="1";
			sort=100;
			name = "依据性资料";
			dictType = basedData.getType();
			dataName = basedData.getNumber()+basedData.getName();
			infoId = basedData.getId();
			save = true;
		}else if(projectcontentinfo.getProjectContentData()!=null){
			//保存工作内容相关数据
			ProjectContentData projectContentData = projectcontentinfo.getProjectContentData();
			if(StringUtils.isNotBlank(projectContentData.getId())){
				ProjectContentData oldData = projectContentDataService.get(projectContentData.getId());
				MyBeanUtils.copyBeanNotNull2Bean(projectContentData, oldData);
				projectContentData = oldData;
			}
			projectContentData.setCompanyId(contentinfo.getCompanyId());
			projectContentData.setOfficeId(contentinfo.getOfficeId());
			projectContentData.setProject(contentinfo.getProject());
			projectContentDataService.save(projectContentData);
			//保存工作内容详情
			if(StringUtils.isNotBlank(projectContentData.getContentDetail())) {
//				if(projectContentData.getType().equals("41")){
//                     ProjectContentData projectContentData1 = new ProjectContentData();
//					 projectContentData1.setCompanyId(contentinfo.getCompanyId());
//					 projectContentData1.setOfficeId(contentinfo.getOfficeId());
//					 projectContentData1.setProject(contentinfo.getProject());
//                     projectContentData1.setType("100");
//                     projectContentData1.setName(projectContentData.getName()+"动态汇总");
//                     projectContentData1.setMaster(projectContentData.getMaster());
//					 projectContentDataService.save(projectContentData1);
//				}
				WorkContentDetailBaseService detailService = WorkContentDetailFactory.getDetailService(projectContentData.getType());
				if(detailService!=null)
					detailService.saveDetails(URLDecoder.decode(projectContentData.getContentDetail(),"UTF-8"), projectContentData.getProject().getId(), projectContentData.getId());
			}
			//保存依据资料信息
			if(projectContentData.getProjectBasedDataList()!=null&&!projectContentData.getProjectBasedDataList().isEmpty()){
				projectContentDataService.saveBasedData(projectContentData.getId(),projectContentData.getProjectBasedDataList());
				projectBasedDataList = projectContentData.getProjectBasedDataList();
			}
			//保存过程控制信息
			if(projectContentData.getProjectControlTableList()!=null&&!projectContentData.getProjectControlTableList().isEmpty()){
				Iterator<ProjectControlTable> iterator = projectContentData.getProjectControlTableList().iterator();
				while (iterator.hasNext()){
					ProjectControlTable controlTable = iterator.next();
					if(projectContentData.getId().equals(controlTable.getPfId())||StringUtils.isBlank(controlTable.getId())){
						iterator.remove();
						continue;
					}
					controlTable.setPfId(projectContentData.getId());
					controlTableDao.updatePfId(controlTable);
				}
				projectControlTableList = projectContentData.getProjectControlTableList();
			}

			WorkContentType contentType = contentTypeService.findUniqueByProperty("type_id", projectContentData.getType());
			WorkContentType parentType = contentTypeService.findUniqueByProperty("type_id", contentType.getParentId());
			count=String.valueOf(Integer.valueOf(parentType.getTypeId())+1);
			sort=Integer.valueOf(count+"00");
			name = parentType.getTypeName();
			dictType = contentType.getTypeId();
			dictName = contentType.getTypeName();
			dataName = projectContentData.getNumber()+projectContentData.getName();
			infoId = projectContentData.getId();
			save = true;
		}else if (projectcontentinfo.getProjectReportData()!=null){
			//保存工作报告相关数据
			ProjectReportData projectReportData = projectcontentinfo.getProjectReportData();
			projectContentDataList = projectReportData.getProjectContentDataList();
			projectReportData.setCompanyId(contentinfo.getCompanyId());
			projectReportData.setOfficeId(contentinfo.getOfficeId());
			projectReportData.setProject(contentinfo.getProject());
			Boolean status = false;
			if (StringUtils.isBlank(projectReportData.getId())){
				status = true;
				projectReportData.setFileStatus("1");
			}
			if (type==1){
				//暂存
				projectReportData.setStatus("1");
				String num = projectReportData.getNumber();
				if(StringUtils.isNotBlank(num)){
					projectReportNumService.updateNum(num);
				}
				projectReportDataService.save(projectReportData);
			}else {
				//送审
				Map<String, Object> variables = Maps.newHashMap();
				projectReportData.setStatus("2");
				String processInstanceId = "";
				//判断是否存在撤回
				if (StringUtils.isNotBlank(projectReportData.getId())){
					ProjectReportData old = projectReportDataService.get(projectReportData.getId());
					if (StringUtils.isNotBlank(old.getProcessInstanceId())){
						processInstanceId = old.getProcessInstanceId();
					}
				}
				//获取项目信息
				ProjectRecords projectRecord = projectRecordsService.getMasters(projectcontentinfo.getProject().getId());
				projectcontentinfo.setProject(projectRecord);
				if (type == 2) {
					//启动流程
					String str = projectReportDataService.save(projectReportData, variables, processInstanceId, projectcontentinfo.getProject().getProjectLeaders());
					if (!str.equals("true")){
						return str;
					}
				}
			}
			Office company = UserUtils.getSelectCompany();
			Office office = UserUtils.getSelectOffice();
			String reportDataName = projectReportData.getName();
			count="8";
			sort=800;
			name = "报告";
			dictType = projectReportData.getType();
			dataName = projectReportData.getName();
			infoId = projectReportData.getId();
			save =true;
			//生成工作内容相关工作内容
			if (projectContentDataList!=null && projectContentDataList.size()!=0){
				projectReportDataService.deleteReportDataInfo(projectReportData);
				for (ProjectContentData data:projectContentDataList) {
					if (data.getDelFlag().equals("0")){
						projectContentDataService.saveReportContent(data.getId(),projectReportData.getId(),"1");
					}
				}
			}
			//保存相关依据资料信息
			if(projectReportData.getProjectBasedDataList()!=null&&!projectReportData.getProjectBasedDataList().isEmpty()){
				projectReportDataService.deleteReportDataBased(projectReportData);
				for (ProjectBasedData data:projectReportData.getProjectBasedDataList()) {
					if (data.getDelFlag().equals("0")){
						projectContentDataService.saveReportContent(data.getId(),projectReportData.getId(),"3");
					}
				}
			}
			//生成报告送审tree数据
			List<WorkReviewAudit> workReviewAudits = new ArrayList<>();
			if (projectReportData.getProjectReviewList()!=null && projectReportData.getProjectReviewList().size()!=0){
				for (WorkReviewAudit workReviewAudit:projectReportData.getProjectReviewList()){
					String remarks = workReviewAudit.getRemarks();
					WorkReviewStandard reviewStandard = workReviewStandardService.get(workReviewAudit.getId());
					if (reviewStandard==null){
						workReviewAudit = workReviewStandardService.getAudit(workReviewAudit.getId());
						workReviewAudit.setRemarks(remarks);
						workReviewAudits.add(workReviewAudit);
					}else{
						workReviewAudit.setReportId(infoId);
						workReviewAudit.setMaxDeduct(reviewStandard.getMaxDeduct());
						workReviewAudit.setOrderNum(reviewStandard.getOrderNum());
						workReviewAudit.setStandardDetail(reviewStandard.getStandardDetail());
						workReviewAudit.setSort(reviewStandard.getSort());
						workReviewAudit.setId(reviewStandard.getId());
						workReviewAudit.setType("1");
						workReviewAudit.setParentIds("0,");
						workReviewAudit.setParent(new WorkReviewAudit("0"));
						workReviewAudit.preInsert();
						workReviewAudit.setRemarks(remarks);
						workReviewAudits.add(workReviewAudit);
					}
				}
			}
			if (!status) {
                workReviewStandardService.deleteAuditType(infoId);
            }
			if (workReviewAudits!=null && workReviewAudits.size()!=0){
				for (WorkReviewAudit workReviewAudit:workReviewAudits){
					workReviewStandardService.saveAudit(workReviewAudit);
				}
			}
			//保存tree数据
			saveReportTree(projectcontentinfo,status,company,office,reportDataName,infoId,attachmentList,projectReportData.getReviewStandard(),1);
		}
		//保存附件+tree
		if (attachmentList!=null && attachmentList.size()!=0) {
			//附件信息
			for (Workattachment workattachment : attachmentList) {
				if (workattachment.getId() == null) {
					continue;
				}
				if (workattachment.DEL_FLAG_NORMAL.equals(workattachment.getDelFlag())) {
					workattachment.setAttachmentId(infoId);
					if (count.equals("1")){
						workattachment.setAttachmentFlag("84");
					}else if (count.equals("8")){
						workattachment.setAttachmentFlag("86");
					}
					workattachment.setAttachmentUser(UserUtils.getUser().getId());
					if (StringUtils.isBlank(workattachment.getId()) || "null".equals(workattachment.getId())) {
						workattachment.preInsert();
						workattachmentDao.insert(workattachment);
						if (projectcontentinfo.getProjectReportData()!=null && StringUtils.isNotBlank(projectcontentinfo.getProjectReportData().getId())) {
							try {
								signatureDocumentService.createIsignature(workattachment.getUrl(), workattachment.getAttachmentName(), workattachment.getId(), projectcontentinfo.getProjectReportData().getName());
							} catch (Exception e) {
								logger.info("PDF转换失败：" + e);
							}
						}
					} else {
						workattachment.preUpdate();
						workattachmentDao.update(workattachment);
					}
				} else {
					workattachmentDao.delete(workattachment);
				}
			}
		}
		//生成项目工作内容tree数据
		if (save) {
			if (projectcontentinfo.getParentIds().equals("0,")) {
				parentIds += contentinfo.getId() + ",";
                parentId = contentinfo.getId();
				if (contentinfo != null && StringUtils.isNotBlank(contentinfo.getId())) {
					Projectcontentinfo select = new Projectcontentinfo();
					select.setParentIds(parentIds);
					select.setType(count);
					select.setProject(projectcontentinfo.getProject());
					List<Projectcontentinfo> infos = dao.findListByProjectAndType(select);
					if (infos == null || infos.size()==0) {
                        select.setParent(parent);
						select.setSort(sort);
						select.setCompanyId(contentinfo.getCompanyId());
						select.setOfficeId(contentinfo.getOfficeId());
						select.setName(name);
						save(select);
						parentIds += select.getId() + ",";
                        parentId = select.getId();
						parent = select;
						sort += 10;
					} else {
						Projectcontentinfo info = infos.get(0);
//							sort = info.getSort() + 10;
						parent = info;
						parentIds = info.getParentIds() + info.getId() + ",";
                        parentId = info.getId();
					}
				}
			} else {
				if (StringUtils.isBlank(projectcontentinfo.getDictType())) {
					parent = projectcontentinfo;
					parentIds = projectcontentinfo.getParentIds() + projectcontentinfo.getId() + ",";
                    parentId = projectcontentinfo.getId();
				} else {
					parentIds = projectcontentinfo.getParentIds();
                    parentId = projectcontentinfo.getParentId();
				}
			}
			if (!count.equals("8")) {
				Projectcontentinfo select1 = new Projectcontentinfo();
				List<Projectcontentinfo> projectcontentinfos = dao.findType(projectcontentinfo.getProject().getId(),name);
				if(projectcontentinfos.size()>0){
					select1.setParent(projectcontentinfos.get(0));
				}else {
					select1.setParent(new Projectcontentinfo(parentId));
				}
				select1.setType(count);
				select1.setDictType(dictType);
				select1.setProject(projectcontentinfo.getProject());
				List<Projectcontentinfo> cinfos = dao.findListByProjectAndDictType(select1);
				if (cinfos == null || cinfos.size() == 0) {
					select1.setDictType(null);
					Integer maxSort = dao.queryMaxSort(select1);
					if (maxSort!=null){
						sort = maxSort;
					}
					sort += 10;
                    select1.setParent(parent);
                    select1.setParentIds(parentIds);
					select1.setSort(sort);
					select1.setDictType(dictType);
					select1.setCompanyId(contentinfo.getCompanyId());
					select1.setOfficeId(contentinfo.getOfficeId());
					select1.setName(StringUtils.isBlank(dictName) ? dictType : dictName);
					List<Projectcontentinfo> projectcontentinfoList = dao.findType(projectcontentinfo.getProject().getId(),dictName);
					if(projectcontentinfoList.size()==0) {
						this.save(select1);
						parentIds += select1.getId() + ",";
						parentId = select1.getId();
						parent = select1;
					}else {
						parent = projectcontentinfoList.get(0);
						parentId = projectcontentinfoList.get(0).getId();
						parentIds += parentId + ",";
					}
				} else {
					Projectcontentinfo cinfo = cinfos.get(0);
//						sort = cinfo.getSort() + 10;
					parent = cinfo;
					parentIds = cinfo.getParentIds() + cinfo.getId() + ",";
					parentId = cinfo.getId();
				}
			}
			Projectcontentinfo projectcontent = this.getByInfoId(infoId);
			if(projectcontent == null){
				Projectcontentinfo select2 = new Projectcontentinfo();
				select2.setParent(new Projectcontentinfo(parentId));
				select2.setType(count);
				select2.setDictType(dictType);
				select2.setProject(projectcontentinfo.getProject());
				Integer maxSort = dao.queryMaxSort(select2);
				if (maxSort!=null){
					sort = maxSort;
				}
				sort += 1;
				projectcontent = new Projectcontentinfo();
				projectcontent.setParentIds(parentIds);
				projectcontent.setType(count);
				projectcontent.setDictType(dictType);
				projectcontent.setProject(projectcontentinfo.getProject());
				projectcontent.setParent(parent);
				projectcontent.setSort(sort);
				projectcontent.setCompanyId(contentinfo.getCompanyId());
				projectcontent.setOfficeId(UserUtils.getSelectOffice().getId());
				projectcontent.setName(dataName);
				projectcontent.setInfoId(infoId);
			}else {
				projectcontent.setName(dataName);
				dao.updateByLinkId(projectcontent.getId(),dataName);
			}
			this.save(projectcontent);
			if(projectBasedDataList!=null&&projectBasedDataList.size()!=0){
				this.createBasedMenu(projectcontent,projectBasedDataList);
			}
			if(projectControlTableList!=null&&projectControlTableList.size()!=0){
				this.createCtrlMenu(projectcontent,projectControlTableList);
			}
		}
		return "true";
	}

	//生成工作内容下的依据资料菜单
	private void createBasedMenu(Projectcontentinfo projectcontent, List<ProjectBasedData> projectBasedDataList) {
		if(projectcontent==null||projectBasedDataList==null||projectBasedDataList.isEmpty()){
			return;
		}
		Projectcontentinfo select2 = new Projectcontentinfo();
		select2.setParent(projectcontent);
		select2.setProject(projectcontent.getProject());
		select2.setName("依据资料");
		List<Projectcontentinfo> infos = dao.findListByParentSelective(select2);
		if (infos==null || infos.isEmpty()){
			String parentIds = projectcontent.getParentIds()+ projectcontent.getId() + ",";
			select2.setParentIds(parentIds);
			select2.setSort(Integer.valueOf(projectcontent.getSort()+"0"));
			select2.setType("1");
			select2.setCompanyId(projectcontent.getCompanyId());
			select2.setOfficeId(UserUtils.getSelectOffice().getId());
			save(select2);
		}else {
			select2 = infos.get(0);
		}
		Projectcontentinfo newRecord = new Projectcontentinfo();
		newRecord.setParent(select2);
		newRecord.setType(select2.getType());
		newRecord.setProject(select2.getProject());
		newRecord.setCompanyId(select2.getCompanyId());
		newRecord.setOfficeId(select2.getOfficeId());
		String parentIds = select2.getParentIds()+ select2.getId() + ",";
		newRecord.setParentIds(parentIds);
		//计算sort
		int sort = Integer.valueOf(select2.getSort()+"0");
		Integer maxSort = dao.queryMaxSort(newRecord);
		if (maxSort!=null){
			sort = maxSort;
		}
		for (ProjectBasedData basedData : projectBasedDataList) {
			Projectcontentinfo infoId = dao.getByInfoId(basedData.getId());
			newRecord.setId(null);
			sort += 1;
			newRecord.setSort(sort);
			newRecord.setName(basedData.getNumber()+basedData.getName());
			newRecord.setInfoId(basedData.getId());
			newRecord.setLinkId(infoId.getId());
			newRecord.setDictType(basedData.getType());
			save(newRecord);
		}
	}
	//生成工作内容下的控制表格菜单
	private void createCtrlMenu(Projectcontentinfo projectcontent, List<ProjectControlTable> projectControlTableList) {
		if(projectcontent==null||projectControlTableList==null||projectControlTableList.isEmpty()){
			return;
		}
		try {
			Projectcontentinfo select = new Projectcontentinfo();
			select.setParent(projectcontent);
			select.setProject(projectcontent.getProject());
			select.setCompanyId(projectcontent.getCompanyId());
			select.setOfficeId(projectcontent.getOfficeId());
			String parentIds = projectcontent.getParentIds()+projectcontent.getId()+",";
			select.setParentIds(parentIds);
			int sort = Integer.valueOf(projectcontent.getSort()+"1");
			Integer maxSort = dao.queryMaxSort(select);
			if (maxSort!=null){
				sort = maxSort+1;
			}
			for (ProjectControlTable controlTable : projectControlTableList) {
				select.setName(controlTable.getProcessName());
				List<Projectcontentinfo> list = dao.findListByParentSelective(select);
				if(list==null||list.isEmpty()){
					//创建第五级菜单
					select.setId(null);
					select.setType("10");
					select.setDictType(controlTable.gettType());
					select.setSort(sort);
					save(select);
				}else {
					select = list.get(0);
				}
				String newParentIds = select.getParentIds()+select.getId()+",";
				Projectcontentinfo newContentInfo = new Projectcontentinfo();
				MyBeanUtils.copyBeanNotNull2Bean(select,newContentInfo);
//                newContentInfo.setSort();
				newContentInfo.setId(null);
				newContentInfo.setParent(select);
				newContentInfo.setName(controlTable.gettName());
				newContentInfo.setParentIds(newParentIds);
				int newsort = Integer.valueOf(select.getSort()+"1");
				Integer maxSort1 = dao.queryMaxSort(select);
				if (maxSort1!=null){
					newsort = maxSort1+1;
				}
				newContentInfo.setSort(newsort);
				newContentInfo.setType("10");
				newContentInfo.setDictType(controlTable.gettType());
				newContentInfo.setInfoId(controlTable.getId());
//                newContentInfo.setLinkId(controlTable.getId());
				save(newContentInfo);
			}
		} catch (Exception e) {
			logger.error("创建控制表格菜单异常。工作内容ID："+projectcontent.getInfoId(),e);
		}
	}


	@Transactional(readOnly = false)
	public Boolean saveReportTree(Projectcontentinfo projectcontentinfo,Boolean save,Office company,Office office,String name,String infoId,List<Workattachment> attachmentList,String reviewType,int type) {
	    if (!save){
			Projectcontentinfo info = new Projectcontentinfo();
			info.setInfoId(infoId);
			info.setProject(projectcontentinfo.getProject());
			deleteChange(info);
			workReviewStandardService.deleteAudit(infoId);
		}
		WorkReviewStandard workReviewStandard = new WorkReviewStandard();
		workReviewStandard.setStandardDetail(projectcontentinfo.getName());
		String reviewIds = "0,"+reviewType+",";
		workReviewStandard.setParentIds(reviewIds);
		workReviewStandard.setType(reviewType);
		List<WorkReviewStandard> workReviewStandards = workReviewStandardService.findListByType(workReviewStandard);
		List<WorkReviewStandard> workReviewStandardList = new ArrayList<>();
		Map<String,String> map = new HashMap<>();
		for (WorkReviewStandard reviewStandard:workReviewStandards){
			int orderNum = Integer.parseInt(reviewStandard.getOrderNum());
			if (orderNum>999){
				WorkReviewAudit workReviewAudit = new WorkReviewAudit();
				workReviewAudit.setReportId(infoId);
				workReviewAudit.setMaxDeduct(reviewStandard.getMaxDeduct());
				workReviewAudit.setOrderNum(reviewStandard.getOrderNum());
				workReviewAudit.setStandardDetail(reviewStandard.getStandardDetail());
				workReviewAudit.setSort(reviewStandard.getSort());
				workReviewAudit.preInsert();
				if (orderNum>999 && orderNum<2000){
					/*workReviewAudit.setType("1");
					workReviewAudit.setParent(new WorkReviewAudit("0"));
					workReviewAudit.setParentIds("0,");*/
					workReviewAudit = new WorkReviewAudit();
				}else if (orderNum>2000 && orderNum<3000){
					workReviewAudit.setType("2");
					workReviewAudit.setParent(new WorkReviewAudit("0"));
					workReviewAudit.setParentIds("0,");
				}else if (orderNum>3000 && orderNum<4000){
					workReviewAudit.setType("3");
					workReviewAudit.setParent(new WorkReviewAudit("0"));
					workReviewAudit.setParentIds("0,");
				}else if (orderNum>4000 && orderNum<10000){
					map.put(reviewStandard.getId(),workReviewAudit.getId());
					workReviewAudit.setType("4");
					workReviewAudit.setParent(new WorkReviewAudit("0"));
					workReviewAudit.setParentIds("0,");
				}else {
					workReviewStandardList.add(reviewStandard);
				}
				if (StringUtils.isNotBlank(workReviewAudit.getType())) {
					workReviewStandardService.saveAudit(workReviewAudit);
				}
			}
		}
		if (workReviewStandardList!=null && workReviewStandardList.size()!=0) {
			for ( int i=0;i< workReviewStandardList.size();i++) {
				WorkReviewStandard reviewStandard = workReviewStandardList.get(i);
				if (reviewStandard.getParent() != null && StringUtils.isNotBlank(reviewStandard.getParent().getId())) {
					String id = map.get(reviewStandard.getParent().getId());
					if (StringUtils.isNotBlank(id)){
						WorkReviewAudit reviewAudit = new WorkReviewAudit();
						reviewAudit.setReportId(infoId);
						reviewAudit.setMaxDeduct(reviewStandard.getMaxDeduct());
						reviewAudit.setOrderNum(reviewStandard.getOrderNum());
						reviewAudit.setStandardDetail(reviewStandard.getStandardDetail());
						reviewAudit.setSort(reviewStandard.getSort());
						reviewAudit.setParent(new WorkReviewAudit(id));
						reviewAudit.setParentIds("0,"+id+",");
						reviewAudit.setType("5");
						reviewAudit.preInsert();
						workReviewStandardService.saveAudit(reviewAudit);
					}
				}

			}
		}
		String parentId = "";
		String parentIds = "";
		if (true) {
			Projectcontentinfo projectcontent = new Projectcontentinfo();
			projectcontent.setParent(new Projectcontentinfo("0"));
			projectcontent.setParentIds("0,");
			projectcontent.setSort(30);
			projectcontent.setCompanyId(company.getId());
			projectcontent.setOfficeId(office.getId());
			projectcontent.setProject(projectcontentinfo.getProject());
			projectcontent.setName(name);
			projectcontent.setInfoId(infoId);
			this.insertChange(projectcontent);
			parentId = projectcontent.getId();
			parentIds = "0,"+projectcontent.getId()+",";
		}
		List<Workattachment> list = new ArrayList<>();
		if (type == 1){
			list = projectReportDataService.getWorkattachments(infoId);
		}else {
			list = projectReportChangeService.getWorkattachments(infoId);
		}
		String id = "";
		String ids = "";
		if (true){
			if (list!=null && list.size()!=0){
				Projectcontentinfo projectcontent = new Projectcontentinfo();
				projectcontent.setParent(new Projectcontentinfo(parentId));
				projectcontent.setParentIds(parentIds);
				projectcontent.setSort(100);
				projectcontent.setCompanyId(company.getId());
				projectcontent.setOfficeId(office.getId());
				projectcontent.setProject(projectcontentinfo.getProject());
				projectcontent.setName("报告文件");
				projectcontent.setInfoId(infoId);
				projectcontent.setType("1");
				this.insertChange(projectcontent);
				id = projectcontent.getId();
				ids = parentIds + ","+projectcontent.getId();
				for (int i = 0;i<list.size();i++) {
					Workattachment workattachment = list.get(i);
					if (StringUtils.isNotBlank(workattachment.getAttachmentName())){
						Projectcontentinfo content = new Projectcontentinfo();
						content.setParent(new Projectcontentinfo(id));
						content.setParentIds(ids);
						content.setSort(200+10*i);
						content.setCompanyId(company.getId());
						content.setOfficeId(office.getId());
						content.setProject(projectcontentinfo.getProject());
						String attachmentNameNoEx = getFileNameNoEx(workattachment.getAttachmentName());
						content.setName(attachmentNameNoEx);
						content.setInfoId(infoId);
						content.setType("1");
						content.setDictType("0");
						//content.setInfoId(workattachment.getId());
						content.setRemarks(workattachment.getUrl());
						this.insertChange(content);
					}
				}
			}
		}
		if (attachmentList!=null && attachmentList.size()!=0) {
			//附件信息
			for (Workattachment workattachment : attachmentList) {
				if (workattachment.getId() == null) {
					continue;
				}
				if (workattachment.DEL_FLAG_NORMAL.equals(workattachment.getDelFlag()) && type == 2) {
					workattachment.setAttachmentId(infoId);
					workattachment.setAttachmentFlag("87");
					workattachment.setAttachmentUser(UserUtils.getUser().getId());
					if (StringUtils.isBlank(workattachment.getId()) || "null".equals(workattachment.getId())) {
						workattachment.preInsert();
						workattachmentDao.insert(workattachment);
						if (projectcontentinfo.getProjectReportData()!=null && StringUtils.isNotBlank(projectcontentinfo.getProjectReportData().getId())) {
							try {
								signatureDocumentService.createIsignature(workattachment.getUrl(), workattachment.getAttachmentName(), workattachment.getId(), projectcontentinfo.getProjectReportData().getName());
							} catch (Exception e) {
								logger.info("PDF转换失败：" + e);
							}
						}
					} else {
						workattachment.preUpdate();
						workattachmentDao.update(workattachment);
					}
				} else {
					workattachmentDao.delete(workattachment);
				}
			}
			if (true){
				if (StringUtils.isBlank(id)){
					Projectcontentinfo projectcontent = new Projectcontentinfo();
					projectcontent.setParent(new Projectcontentinfo(parentId));
					projectcontent.setParentIds(parentIds);
					projectcontent.setSort(100);
					projectcontent.setCompanyId(company.getId());
					projectcontent.setOfficeId(office.getId());
					projectcontent.setProject(projectcontentinfo.getProject());
					projectcontent.setName("报告文件");
					projectcontent.setInfoId(infoId);
					projectcontent.setType("1");
					this.insertChange(projectcontent);
					id = projectcontent.getId();
					ids = parentIds +projectcontent.getId()+",";
				}

				for (int i = 0;i<attachmentList.size();i++) {
					Workattachment workattachment = attachmentList.get(i);
					if (StringUtils.isNotBlank(workattachment.getAttachmentName())){
						Projectcontentinfo content = new Projectcontentinfo();
						content.setParent(new Projectcontentinfo(id));
						content.setParentIds(ids);
						content.setSort(300+10*i);
						content.setCompanyId(company.getId());
						content.setOfficeId(office.getId());
						content.setProject(projectcontentinfo.getProject());
						String attachmentNameNoEx = getFileNameNoEx(workattachment.getAttachmentName());
						content.setName(attachmentNameNoEx);
						content.setRemarks(workattachment.getUrl());
						content.setInfoId(infoId);
						content.setDictType("0");
						content.setType("1");
						this.insertChange(content);
					}
				}
			}
		}
		if (true) {
			Projectcontentinfo projectcontent = new Projectcontentinfo();
			projectcontent.setParent(new Projectcontentinfo(parentId));
			projectcontent.setParentIds(parentIds);
			projectcontent.setSort(400);
			projectcontent.setCompanyId(company.getId());
			projectcontent.setOfficeId(office.getId());
			projectcontent.setProject(projectcontentinfo.getProject());
			projectcontent.setName("复核底稿");
			projectcontent.setInfoId(infoId);
			projectcontent.setType("2");
			this.insertChange(projectcontent);
			String id1 = projectcontent.getId();
			String ids1 = parentIds +projectcontent.getId()+",";
			Projectcontentinfo content = new Projectcontentinfo();
			content.setType("2");
			content.setParent(new Projectcontentinfo(id1));
			content.setParentIds(ids1);
			content.setCompanyId(company.getId());
			content.setOfficeId(office.getId());
			content.setProject(projectcontentinfo.getProject());
			content.setInfoId(infoId);
			content.setName("项目负责人复核");
			content.setSort(420);
			content.setDictType("2");
			this.insertChange(content);
//			content.setDictType("3");
//			content.setName("二级复核");
//			content.setSort(430);
//			this.insertChange(content);
			content.setDictType("4");
			content.setName("总审部校核");
			content.setSort(440);
			this.insertChange(content);
			List<ProjectBasedData> list2 = projectcontentinfo.getProjectReportData().getProjectBasedDataList();
			if (list2!=null && list2.size()!=0){
				for (int i = 0;i<list2.size();i++) {
					ProjectBasedData projectBasedData = list2.get(i);
					if (projectBasedData.getDelFlag().equals("0")&&StringUtils.isNotBlank(projectBasedData.getId())){
						Projectcontentinfo contentinfoParent = dao.getByInfoId(projectBasedData.getId());
						contentinfoParent.setParent(new Projectcontentinfo(parentId));
						contentinfoParent.setParentIds(parentIds);
						contentinfoParent.setLinkId(projectBasedData.getId());
						contentinfoParent.setType("3");
						contentinfoParent.setInfoId(infoId);
						contentinfoParent.setSort(500);
						this.insertChange(contentinfoParent);
					}

				}
			}
			List<ProjectContentData> list1 = projectcontentinfo.getProjectReportData().getProjectContentDataList();
			if (list1!=null && list1.size()!=0){
				for (int i = 0;i<list1.size();i++) {
					ProjectContentData projectContentData = list1.get(i);
					if (projectContentData.getDelFlag().equals("0")){
						Projectcontentinfo contentinfoParent = dao.getByInfoId(projectContentData.getId());
						contentinfoParent.setParent(new Projectcontentinfo(parentId));
						contentinfoParent.setParentIds(parentIds);
						contentinfoParent.setLinkId(projectContentData.getId());
						contentinfoParent.setType("4");
						contentinfoParent.setInfoId(infoId);
						contentinfoParent.setSort(600);
						this.insertChange(contentinfoParent);
					}
				}
			}
		}
		return true;
	}

	@Transactional(readOnly = false)
	public Boolean saveChange(Projectcontentinfo projectcontentinfo,int type) {
		String infoId = "";
		String name = "";
		List<Workattachment> attachmentList = projectcontentinfo.getWorkAttachments();
		boolean save = false;
		ProjectRecords projectRecord = projectRecordsService.getMasters(projectcontentinfo.getProject().getId());
		if (projectcontentinfo.getProjectReportData()!=null){
			ProjectReportData projectReportData = projectcontentinfo.getProjectReportData();
			projectReportData.setProject(projectcontentinfo.getProject());
			if (StringUtils.isBlank(projectReportData.getId())){
				projectReportData.setStatus("1");
				save =true;
				ProjectReportData beforeEntity = projectReportChangeService.findByBefore(projectReportData);
				if (beforeEntity!=null && StringUtils.isNotBlank(beforeEntity.getId())){
					projectReportData.setBeforeEntity(beforeEntity);
					projectReportData.setBeforeCount(beforeEntity.getBeforeCount()+1);
				}else {
					beforeEntity = projectReportDataService.get(projectReportData.getReportId());
					projectReportData.setBeforeEntity(beforeEntity);
					projectReportData.setBeforeCount(1);
				}
			}
			if (type==1){
				projectReportData.setStatus("1");
				projectReportChangeService.save(projectReportData);
			}else {
				Map<String, Object> variables = Maps.newHashMap();
				projectReportData.setStatus("2");
				String processInstanceId = "";
				if (StringUtils.isNotBlank(projectReportData.getId())){
					ProjectReportData old = projectReportChangeService.get(projectReportData.getId());
					if (StringUtils.isNotBlank(old.getProcessInstanceId())){
						processInstanceId = old.getProcessInstanceId();
					}
				}
				projectcontentinfo.setProject(projectRecord);
				if (StringUtils.isBlank(projectReportData.getCompanyId())){
					projectReportData.setCompanyId(projectRecord.getCompany().getId());
					projectReportData.setOfficeId(projectRecord.getOffice().getId());
				}
				if (type==2) {
					String str = projectReportChangeService.save(projectReportData, variables, processInstanceId, projectcontentinfo.getProject().getProjectLeaders());
					if (!str.equals("true")) {
						return false;
					}
				}
			}
			infoId = projectReportData.getId();
			ProjectReportData reportData = projectReportDataService.get(projectReportData.getReportId());
			ProjectReportData projectReportChange = projectReportChangeService.get(projectReportData.getReportId());
			if (projectReportChange==null || StringUtils.isBlank(projectReportChange.getId())){
				reportData.setBeforeCount(0);
				projectReportChangeService.insert(reportData);
			}
			reportData.setStatus("8");
				/*if ("3".equals(reportData.getFileStatus())){
					reportData.setFileStatus("1");
				}*/
			projectReportDataService.save(reportData);
			ProjectReportRecord projectReportRecord = new ProjectReportRecord();
			projectReportRecord.setReport(reportData);
			projectReportRecord.setStatus("2");
			List<ProjectReportRecord> projectReportRecords = projectReportRecordService.findList(projectReportRecord);
			if (projectReportRecords!=null && projectReportRecords.size()!=0){
				for (ProjectReportRecord reportRecord:projectReportRecords){
					if ("2".equals(reportRecord.getStatus())){
						projectReportRecordService.cancelInvalidate(reportRecord);
					}
				}
			}
			name = projectReportData.getName();
			List<ProjectContentData> projectContentDataList = projectcontentinfo.getProjectReportData().getProjectContentDataList();
			if (projectContentDataList!=null && projectContentDataList.size()!=0){
				projectReportChangeService.deleteReportDataInfo(projectReportData);
				for (ProjectContentData data:projectContentDataList) {
					if (data.getDelFlag().equals("0")&&StringUtils.isNotBlank(data.getId())){
						projectContentDataService.saveReportContent(data.getId(),projectReportData.getId(),"2");
					}
				}
			}
			//保存依据资料信息
			//保存依据资料信息
			if(projectReportData.getProjectBasedDataList()!=null&&!projectReportData.getProjectBasedDataList().isEmpty()){
				projectReportChangeService.deleteReportDataBased(projectReportData);
				for (ProjectBasedData data:projectReportData.getProjectBasedDataList()) {
					if (data.getDelFlag().equals("0")&&StringUtils.isNotBlank(data.getId())){
						projectContentDataService.saveReportContent(data.getId(),projectReportData.getId(),"4");
					}
				}
			}
			List<WorkReviewAudit> workReviewAudits = new ArrayList<>();
			if (projectReportData.getProjectReviewList()!=null && projectReportData.getProjectReviewList().size()!=0){
				for (WorkReviewAudit workReviewAudit:projectReportData.getProjectReviewList()){
					String remarks = workReviewAudit.getRemarks();
					WorkReviewStandard reviewStandard = workReviewStandardService.get(workReviewAudit.getId());
					if (reviewStandard==null){
						workReviewAudit = workReviewStandardService.getAudit(workReviewAudit.getId());
						workReviewAudit.setRemarks(remarks);
						workReviewAudit.preInsert();
						workReviewAudit.setReportId(infoId);
						workReviewAudits.add(workReviewAudit);
					}else{
						workReviewAudit.setReportId(infoId);
						workReviewAudit.setMaxDeduct(reviewStandard.getMaxDeduct());
						workReviewAudit.setOrderNum(reviewStandard.getOrderNum());
						workReviewAudit.setStandardDetail(reviewStandard.getStandardDetail());
						workReviewAudit.setSort(reviewStandard.getSort());
						workReviewAudit.setId(reviewStandard.getId());
						workReviewAudit.setType("1");
						workReviewAudit.setParent(new WorkReviewAudit("0"));
						workReviewAudit.setParentIds("0,");
						workReviewAudit.preInsert();
						workReviewAudit.setRemarks(remarks);
						workReviewAudits.add(workReviewAudit);
					}
				}
			}
			workReviewStandardService.deleteAuditChangeType(infoId);
			if (workReviewAudits!=null && workReviewAudits.size()!=0){
				for (WorkReviewAudit workReviewAudit:workReviewAudits){
					workReviewStandardService.saveAudit(workReviewAudit);
				}
			}
			saveReportTree(projectcontentinfo,save,projectRecord.getCompany(),projectRecord.getOffice(),name,infoId,attachmentList,projectReportData.getReviewStandard(),2);
			return true;
		}else {
			return false;
		}

	}
	@Transactional(readOnly = false)
	public String saveInvalid(Projectcontentinfo projectcontentinfo,int type) {
		ProjectReportData projectReportData= projectcontentinfo.getProjectReportData();
		if (projectReportData!=null){
			projectReportData.setStatus("6");
			projectReportData.setInvalidStatus("1");
			projectReportData.preUpdate();
			projectReportDataService.saveInvalid(projectReportData);
		}
		if (type == 2){
			Map<String, Object> variables = Maps.newHashMap();
			projectReportData.setStatus("6");
			projectReportData.setInvalidStatus("2");
			String invalidProcessInstanceId = "";
			if (StringUtils.isNotBlank(projectReportData.getId())){
				ProjectReportData old = projectReportDataService.get(projectReportData.getId());
				if (StringUtils.isNotBlank(old.getInvalidProcessInstanceId())){
					invalidProcessInstanceId = old.getInvalidProcessInstanceId();
				}
			}
			ProjectRecords projectRecord = projectRecordsService.getMasters(projectcontentinfo.getProject().getId());
			projectcontentinfo.setProject(projectRecord);
			return projectReportDataService.saveInvalid(projectReportData.getId(),projectReportData.getRemarks(),variables,invalidProcessInstanceId);
		}
		return "true";

	}

	@Transactional(readOnly = false)
	public Boolean deleteInfoIdInvalid(String infoId) {
		ProjectReportData projectReportData= projectReportDataService.get(infoId);
		if (projectReportData!=null){
			if (StringUtils.isNotBlank(projectReportData.getInvalidProcessInstanceId())){
				workActivityProcessService.deleteProcessInstanceById(projectReportData.getInvalidProcessInstanceId());
			}
			WorkProjectNotify notify = new WorkProjectNotify();
			notify.setNotifyId(projectReportData.getId());
			List<User> users = workProjectNotifyService.readByNotifyId(notify);
			if (users!=null && users.size()!=0){
				for (User user:users){
					UserUtils.pushMeIm(user.getId());
				}
			}
			projectReportData.preUpdate();
			projectReportDataService.update(projectReportData);
			projectReportData.setStatus("5");
			projectReportData.setRemarks("");
			projectReportDataService.saveInvalid(projectReportData);
			ProjectReportData reportData= projectReportDataService.getNoInvalid(infoId);
			projectReportDataService.updateInvalidProcessInstanceId(reportData);
		}
		return true;
	}

	@Transactional(readOnly = false)
	public void delete(Projectcontentinfo projectcontentinfo) {
		super.delete(projectcontentinfo);
	}

	@Transactional(readOnly = false)
	public void deleteInfoId(String type,String infoId) {
		Projectcontentinfo projectcontentinfo = new Projectcontentinfo();
		projectcontentinfo.setInfoId(infoId);
		Projectcontentinfo info = dao.findByInfoId(projectcontentinfo);
		if (type.equals("8")){
			List<Projectcontentinfo> projectcontentinfos = dao.findListByProjectType(info);
			if (projectcontentinfos != null && projectcontentinfos.size() == 1) {
				Projectcontentinfo projectcontentinfo1 = projectcontentinfos.get(0);
				String ids = projectcontentinfo1.getParentIds();
				String parentIds = ids.replace(projectcontentinfo1.getParent().getId(),"").replace(",,",",");
				projectcontentinfo1.setParentIds(parentIds);
				List<Projectcontentinfo> infos = dao.findListByProject(projectcontentinfo1);
				if (infos != null && infos.size() == 1) {
					dao.delete(infos.get(0));
				}else {
					if (infos != null && infos.size() != 0) {
						for (Projectcontentinfo info2:infos){
							if (info2.getType().equals(type)){
								dao.delete(info2);
								break;
							}
						}
					}
				}
			}
			WorkProjectNotify notify = new WorkProjectNotify();
			notify.setNotifyId(infoId);
			List<User> users = workProjectNotifyService.readByNotifyId(notify);
			if (users!=null && users.size()!=0){
				for (User user:users){
					UserUtils.pushMeIm(user.getId());
				}
			}
		}else {
			List<Projectcontentinfo> projectcontentinfos = dao.findListByProjectAndDictType(info);
			if (projectcontentinfos != null && projectcontentinfos.size() == 1) {
				Projectcontentinfo projectcontentinfo1 = projectcontentinfos.get(0);
				String dictType =projectcontentinfo1.getDictType();
				String ids = projectcontentinfo1.getParentIds();
				String parentIds = ids.replace(projectcontentinfo1.getParent().getId(),"").replace(",,",",");
				projectcontentinfo1.setParentIds(parentIds);
				List<Projectcontentinfo> infos = dao.findListByProjectAndTypes(projectcontentinfo1);
				if (infos != null && infos.size() == 1) {
					Projectcontentinfo info1 = infos.get(0);
					String infoIds = projectcontentinfo1.getParentIds();
					String infoParentIds = infoIds.replace(info1.getParent().getId(),"").replace(",,",",");
					info1.setParentIds(infoParentIds);
					List<Projectcontentinfo> infoList = dao.findListByProject(info1);
					if (infoList != null && infoList.size() == 1){
						dao.delete(infoList.get(0));
					}else {
						for (Projectcontentinfo info2:infoList){
							if (info2.getType().equals(type)){
								dao.delete(info2);
								break;
							}
						}
					}
					dao.delete(infos.get(0));
				}else {
					if (infos != null && infos.size() != 0) {
						for (Projectcontentinfo info2:infos){
							if (info2.getDictType().equals(dictType)){
								dao.delete(info2);
								break;
							}
						}
					}
				}
			}
		}

		dao.deleteInfoId(info);
		if (type.equals("1")) {
			ProjectBasedData projectBasedData = projectBasedDataService.get(infoId);
			if (projectBasedData.getWorkAttachments() != null && projectBasedData.getWorkAttachments().size() != 0) {
				for (Workattachment workattachment : projectBasedData.getWorkAttachments()) {
					workattachmentDao.delete(workattachment);
				}
			}
			projectBasedDataService.delete(projectBasedData);
		}else if (type.equals("8")){
			ProjectReportData projectReportData = projectReportDataService.get(infoId);
			if (projectReportData.getWorkAttachments() != null && projectReportData.getWorkAttachments().size() != 0) {
				for (Workattachment workattachment : projectReportData.getWorkAttachments()) {
					workattachmentDao.delete(workattachment);
				}
			}
			if (StringUtils.isNotBlank(projectReportData.getProcessInstanceId())){
				workActivityProcessService.deleteProcessInstanceId(projectReportData.getProcessInstanceId());
			}
			if (StringUtils.isNotBlank(projectReportData.getInvalidProcessInstanceId())){
				workActivityProcessService.deleteProcessInstanceId(projectReportData.getInvalidProcessInstanceId());
			}
			Projectcontentinfo infos = new Projectcontentinfo();
			infos.setInfoId(projectReportData.getId());
			infos.setProject(projectReportData.getProject());
			workReviewStandardService.deleteAudit(infoId);
			projectContentChangeDao.deleteChange(infos);
			projectReportDataService.delete(projectReportData);
		}else {
			//删除工作内容
			ProjectContentData contentData = projectContentDataService.get(infoId);
			projectContentDataService.delete(contentData);
			//删除子菜单
			String parentIds  = info.getParentIds()+info.getId()+",";
			dao.deleteInfosByParent(parentIds);
		}

	}

	@Transactional(readOnly = false)
	public void deleteInfoIdChange(String infoId) {
		ProjectReportData projectReportData = projectReportChangeService.get(infoId);
		String reportId = projectReportData.getReportId();
		if (projectReportData.getWorkAttachments() != null && projectReportData.getWorkAttachments().size() != 0) {
			for (Workattachment workattachment : projectReportData.getWorkAttachments()) {
				if (workattachment.getAttachmentFlag().equals("87")){
					workattachmentDao.delete(workattachment);
				}
			}
		}
		WorkProjectNotify notify = new WorkProjectNotify();
		notify.setNotifyId(projectReportData.getId());
		List<User> users = workProjectNotifyService.readByNotifyId(notify);
		if (users!=null && users.size()!=0){
			for (User user:users){
				UserUtils.pushMeIm(user.getId());
			}
		}
		ProjectReportData reportData= projectReportDataService.get(reportId);
		if (projectReportData!=null){
			if (StringUtils.isNotBlank(projectReportData.getProcessInstanceId())){
				workActivityProcessService.deleteProcessInstanceId(projectReportData.getProcessInstanceId());
			}
			reportData.setStatus("5");
			reportData.setRemarks("");
			projectReportDataService.saveInvalid(reportData);
		}
		projectReportChangeService.deleteTree(projectReportData);
		if (projectReportData.getBeforeCount()==1){
			projectReportChangeService.delete(new ProjectReportData(projectReportData.getReportId()));
		}
		projectReportChangeService.delete(projectReportData);

	}

	/*
	 * Java文件操作 获取文件扩展名
	 *
	 *  Created on: 2011-8-2
	 *      Author: blueeagle
	 */
	public static String getExtensionName(String filename) {
		if ((filename != null) && (filename.length() > 0)) {
			int dot = filename.lastIndexOf('.');
			if ((dot >-1) && (dot < (filename.length() - 1))) {
				return filename.substring(dot + 1);
			}
		}
		return filename;
	}
	/*
	 * Java文件操作 获取不带扩展名的文件名
	 *
	 *  Created on: 2011-8-2
	 *      Author: blueeagle
	 */
	public static String getFileNameNoEx(String filename) {
		if ((filename != null) && (filename.length() > 0)) {
			int dot = filename.lastIndexOf('.');
			if ((dot >-1) && (dot < (filename.length()))) {
				return filename.substring(0, dot);
			}
		}
		return filename;
	}

}