/**
 * 
 */
package com.unis.flowable.server.service;

import com.unis.common.utils.CurrentUtil;
import com.unis.common.utils.ResponseWrapper;
import com.unis.flowable.client.OaClient;
import com.unis.flowable.common.vo.SysEventMessageInfoDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;


/** 
 * @ClassName SysEventMessageService
 * @Description: 
 * @author: zhaoxd
 * @date: 2019年2月15日 下午1:52:07
 * @version v1.0
 */
@Service
@Slf4j
public class SysEventMessageService {

	@Autowired
	OaClient oaClient;

	@Value("192.168.123.58:88")
	private String domain;

	@Value("192.168.123.58:88")
	private String irpt;

	/** @Description 查询列表
	 * @param eventFlg
	 * @return
	 * @throws
	 * @version v1.0
	 * @author zhaoxd
	 * @date 2019年2月15日
	 */
	/*public Page<SysEventMessageInfoDto> queryListByPage(Integer eventFlg, Integer page, Integer size, Integer eventType) {
		Sort sort = new Sort(Sort.Direction.ASC, "eventFlg").and(new Sort(Sort.Direction.ASC, "id"));
		Pageable pageable = PageRequest.of( page - 1, size, sort );
	        Specification<SysEventMessageInfo> specification =  new Specification <SysEventMessageInfo>() {
	            @Override
	            public Predicate toPredicate(Root<SysEventMessageInfo> root, CriteriaQuery <?> query, CriteriaBuilder cb) {
	                List <Predicate> list = new ArrayList <Predicate>();
	                if (eventFlg!=null) {
	                    list.add( cb.equal( root.get( "eventFlg" ).as( Integer.class ),eventFlg) );
	                }
	                list.add( cb.equal( root.get( "eventType" ).as( Integer.class ),  eventType) );
	                list.add( cb.equal( root.get( "receivePersonId" ).as( String.class ), InsertUserInfoUtil.getUserId()) );
	                return cb.and( list.toArray( new Predicate[list.size()] ) );
	            }
	        };
	        Page <SysEventMessageInfo> sysEventMessageInfoList = sysEventMessageInfoRepository.findAll(specification, pageable );

	        List<SysEventMessageInfoDto> list = new ArrayList<SysEventMessageInfoDto>();

	        for (SysEventMessageInfo sysEventMessageInfo : sysEventMessageInfoList.getContent()) {
	        	SysEventMessageInfoDto sysEventMessageInfoDto = LsBeanUtils.copyProperties(sysEventMessageInfo, SysEventMessageInfoDto.class);
	            list.add(sysEventMessageInfoDto);
	        }
	        Page<SysEventMessageInfoDto> SysEventMessageInfoDtoList = new PageImpl<SysEventMessageInfoDto>(list, sysEventMessageInfoList.getPageable(), sysEventMessageInfoList.getTotalElements());
	        return SysEventMessageInfoDtoList;

	    }
	*//** @Description 首页待办列表展示
	 * @param
	 * @param
	 * @param
	 * @param
	 * @return
	 * @throws
	 * @version v1.0
	 * @author zhaoxd
	 * @return
	 * @date 2018年12月29日
	 *//*
	public Map<String,Object> findDBList()throws Exception {
        StringBuffer sql = new StringBuffer();
        sql.append("select count(id) as num ,  c.EVENT_INFO,");
        sql.append("c.LINK_URL,c.MSG_INFO ");
        sql.append(" from SYS_EVENT_MESSAGE_INFO c ");
        sql.append("where c.EVENT_TYPE ='1' and c.EVENT_FLG='0' ");
      //人
        sql.append(" and RECEIVE_PERSON_ID = '" + InsertUserInfoUtil.getUserId() + "'  group by c.EVENT_INFO,c.LINK_URL,c.MSG_INFO ");

        //获取返回数据总数
        Long totals =(long) 0;
        //分页
        List<Object[]> dcdbTaskInfoList = entityManager.createNativeQuery(sql.toString()).getResultList();
        List<SysEventMessageInfoDto> list2=new ArrayList<>();
        List<SysEventMessageInfoDto> list3=new ArrayList<>();
        for (Object[] obj : dcdbTaskInfoList) {
        	SysEventMessageInfoDto sysEventMessageInfoDto=new SysEventMessageInfoDto();
             Long pid = obj[0] == null ? null : ((BigDecimal) obj[0]).longValue();
             totals+=pid;
             sysEventMessageInfoDto.setId(pid);
             sysEventMessageInfoDto.setEventInfo(obj[1] == null ? null : obj[1].toString());
             sysEventMessageInfoDto.setLinkUrl(obj[2] == null ? null : obj[2].toString());
             sysEventMessageInfoDto.setMsgInfo(obj[3] == null ? null : obj[3].toString());
             sysEventMessageInfoDto.setEventInfo(sysEventMessageInfoDto.getEventInfo()+","+sysEventMessageInfoDto.getMsgInfo());
             list3.add(sysEventMessageInfoDto);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("list", list3);
        map.put("totals", totals);
        return map;
	}

	public Map<String,Object> findDBList2()throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("select count(id) as num ,  c.EVENT_INFO,");
		sql.append("c.LINK_URL,c.MSG_INFO ");
		sql.append(" from SYS_EVENT_MESSAGE_INFO c ");
		sql.append("where c.EVENT_TYPE ='1' and c.EVENT_FLG='0' ");
		//人
		sql.append(" and RECEIVE_PERSON_ID = '" + InsertUserInfoUtil.getUserId() + "'  group by c.EVENT_INFO,c.LINK_URL,c.MSG_INFO ");

		//获取返回数据总数
		Long totals =(long) 0;
		//分页
		List<Object[]> dcdbTaskInfoList = entityManager.createNativeQuery(sql.toString()).getResultList();
		List<SysEventMessageInfoDto> list2=new ArrayList<>();
		List<SysEventMessageInfoDto> list3=new ArrayList<>();
		for (Object[] obj : dcdbTaskInfoList) {
			SysEventMessageInfoDto sysEventMessageInfoDto=new SysEventMessageInfoDto();
			Long pid = obj[0] == null ? null : ((BigDecimal) obj[0]).longValue();
			totals+=pid;
			sysEventMessageInfoDto.setId(pid);
			sysEventMessageInfoDto.setEventInfo(obj[1] == null ? null : obj[1].toString());
			sysEventMessageInfoDto.setLinkUrl(obj[2] == null ? null : obj[2].toString());
			sysEventMessageInfoDto.setMsgInfo(obj[3] == null ? null : obj[3].toString());
            sysEventMessageInfoDto.setEventInfo(sysEventMessageInfoDto.getEventInfo()+"，"+sysEventMessageInfoDto.getMsgInfo());
            //查询分组内最大时间
            StringBuffer timeSql = new StringBuffer();
            timeSql.append("select max(c.START_TIME) ");
            timeSql.append("from SYS_EVENT_MESSAGE_INFO c ");
            timeSql.append("where c.EVENT_TYPE ='1' and c.EVENT_FLG='0' ");
            timeSql.append("and c.EVENT_INFO = '");
            timeSql.append(obj[1] == null ? null : obj[1].toString() +"' ");
            timeSql.append("and c.LINK_URL = '");
            timeSql.append(obj[2] == null ? null : obj[2].toString() +"' ");
            timeSql.append("and c.MSG_INFO = '");
            timeSql.append(obj[3] == null ? null : obj[3].toString() +"' ");
            timeSql.append("and RECEIVE_PERSON_ID = '" + InsertUserInfoUtil.getUserId() + "'");
            List<String> result = entityManager.createNativeQuery(timeSql.toString()).getResultList();
            String startTime = result.get(0);
            sysEventMessageInfoDto.setStartTime(startTime);
			list3.add(sysEventMessageInfoDto);
		}

		// OA代办
		*//*String urlBase = "/web/xzgl/#/ssoa/open?url=";
		//String urlBefore = "http://" + "sxlscbj:8087" + "/workflow/request/ViewRequest.jsp?requestid=";
		String urlBefore = "http://" + domain + "/workflow/request/ViewRequest.jsp?requestid=";
		String urlCentre = "&_workflowid=";
		String urlAfter = "&_workflowtype=&isovertime=0";
		String[] conditions = new String[0];
		ResponseWrapper oaWrapper = oaClient.queryWaitItems(1, queryWaitCountOa(), queryWaitCountOa(),
				InsertUserInfoUtil.getUserLoginName(), new String[] {});
		log.info(">>>>>>>【首页待办列表】OA平台："+oaWrapper.getData()+"<<<<<<<<<<");
		if(oaWrapper.getInfoCode()==200) {
			List<Map> oaList = (List<Map>) oaWrapper.getData();
			if (oaList.size() > 0) {
				totals += (long) oaList.size();
				for (Map oaMap : oaList) {
					SysEventMessageInfoDto sysEventMessageInfoDto = new SysEventMessageInfoDto();
					//JSONObject oa = new JSONObject();
					String workflowId = oaMap.get("workflowBaseInfo").toString().substring(12, 13);
					String sysName = "行政管理平台";
					sysEventMessageInfoDto.setId(1L);
					sysEventMessageInfoDto.setLinkUrl(urlBefore + (String) oaMap.get("requestId") + urlCentre + workflowId + urlAfter);
					String title = "";
					if (StringUtils.isNotBlank((String) oaMap.get("requestName"))) {
						title = "标题；“" + (String) oaMap.get("requestName") + "”";
					}
					sysEventMessageInfoDto.setEventInfo(sysName + "，" + title + "，" + "您有一个" + (String) oaMap.get("currentNodeName") + "需要处理！");
					sysEventMessageInfoDto.setStartTime((String) oaMap.get("createTime"));
					list3.add(sysEventMessageInfoDto);
				}
			}
		}*//*
		//I平台待办
		ItemFilterVO itemFilterVO = new ItemFilterVO();
		itemFilterVO.setUserId(InsertUserInfoUtil.getUserLoginName());
		ResponseWrapper irptWrapper = irptClient.queryWaitItems(itemFilterVO);
		//ResponseWrapper irptWrapper2 = irptClient.queryWaitDetailItemsNoPage(itemFilterVO);
		log.info(">>>>>>>【首页待办列表】IRPT平台：" + irptWrapper.getData() + "<<<<<<<<<<");
		if(irptWrapper.getInfoCode()==200){
			List<Map> irptList = (List<Map>) irptWrapper.getData();
			if(irptList.size()> 0){
				totals+=(long)irptList.size();
				for (Map irptMap : irptList) {
					SysEventMessageInfoDto sysEventMessageInfoDto = new SysEventMessageInfoDto();
					sysEventMessageInfoDto.setId(1L);
					sysEventMessageInfoDto.setEventInfo((String) irptMap.get("BUSINESSKEY") +"，请您及时处理!");
					String proc_inst_id = (String) irptMap.get("PROC_INST_ID");
					String act_id = (String) irptMap.get("ACT_ID");
					String task_id = (String) irptMap.get("TASK_ID");
					sysEventMessageInfoDto.setLinkUrl("http://"+ irpt +"/irpt/welcome.do?hideframe=true&hidehead=true#navigator:/esmain/workflow/workflowmgr.do?command=todotasks&taskid="+act_id+"&slid="+proc_inst_id+"&activitiId="+task_id+"&workflowShowSubmitVisible=false&rshid=workflow-dotask");
					sysEventMessageInfoDto.setStartTime((String) irptMap.get("CREATE_TIME"));
					list3.add(sysEventMessageInfoDto);

				}
			}
		}

		//根据时间排序
		SysEventMessageService.ListSort(list3);

		Map<String, Object> map = new HashMap<>(2);
		map.put("list", list3);
		map.put("totals", totals);
		return map;
	}*/

	/**
	 * 获取oa待办接口
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> findDBList3()throws Exception {
		// OA代办
		Long totals =(long) 0;
		List<SysEventMessageInfoDTO> list3=new ArrayList<>();
		String urlBase = "/web/xzgl/#/ssoa/open?url=";
		//String urlBefore = "http://" + "sxlscbj:8087" + "/workflow/request/ViewRequest.jsp?requestid=";
		String urlBefore = "http://" + domain + "/workflow/request/ViewRequest.jsp?requestid=";
		String urlCentre = "&_workflowid=";
		String urlAfter = "&_workflowtype=&isovertime=0";
		String[] conditions = new String[0];
		ResponseWrapper oaWrapper = oaClient.queryWaitItems(1, queryWaitCountOa(), queryWaitCountOa(),
				CurrentUtil.getUserAccount(), new String[] {});
		log.info(">>>>>>>【首页待办列表】OA平台:"+oaWrapper.getData()+"<<<<<<<<<<");
		if(oaWrapper.getInfoCode()==200) {
			List<Map> oaList = (List<Map>) oaWrapper.getData();
			if (oaList.size() > 0) {
				totals += (long) oaList.size();
				for (Map oaMap : oaList) {
					SysEventMessageInfoDTO sysEventMessageInfoDto = new SysEventMessageInfoDTO();
					//JSONObject oa = new JSONObject();
					String workflowId = oaMap.get("workflowBaseInfo").toString().substring(12, 13);
					String sysName = "公文待办";
					sysEventMessageInfoDto.setId(1L);
					sysEventMessageInfoDto.setLinkUrl(urlBefore + (String) oaMap.get("requestId") + urlCentre + workflowId + urlAfter);
					String title = "";
					if (StringUtils.isNotBlank((String) oaMap.get("requestName"))) {
						title = "标题:“" + (String) oaMap.get("requestName") + "”";
					}
					sysEventMessageInfoDto.setEventInfo(sysName + "，" + title + "，" + "您有一个" + (String) oaMap.get("currentNodeName") + "需要处理！");
					sysEventMessageInfoDto.setStartTime((String) oaMap.get("createTime"));
					sysEventMessageInfoDto.setStartPersonName(String.valueOf(oaMap.get("creatorName")));
					list3.add(sysEventMessageInfoDto);
				}
			}
		}
		//根据时间排序
		SysEventMessageService.ListSort(list3);

		Map<String, Object> map = new HashMap<>(2);
		map.put("list", list3);
		map.put("totals", totals);
		return map;
	}
	static void ListSort(List<SysEventMessageInfoDTO> list) {
		{    //排序方法
			Collections.sort(list, new Comparator<SysEventMessageInfoDTO>() {
				@Override
				public int compare(SysEventMessageInfoDTO s1, SysEventMessageInfoDTO s2) {
					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
					try {
						// format.format(o1.getTime()) 表示 date转string类型 如果是string类型就不要转换了
						Date dt1 = format.parse(s1.getStartTime());
						Date dt2 = format.parse(s2.getStartTime());
						// 这是由大向小排序   如果要由小向大转换比较符号就可以
						if (dt1.getTime() < dt2.getTime()) {
							return 1;
						} else if (dt1.getTime() > dt2.getTime()) {
							return -1;
						} else {
							return 0;
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					return 0;
				}

			});
		}

	}


	public Integer queryWaitCountOa() {
		String userloginName = CurrentUtil.getUserAccount();
		ResponseWrapper oaWrapper = oaClient.queryWaitCount(CurrentUtil.getUserAccount(), new String[] {});
		String data=oaWrapper.getData().toString();
		if(data.equals("")){
			return 0;
		}
		return (Integer) oaWrapper.getData();
	}
/*
	/** @Description 首页通知列表展示
	 * @param
	 * @param
	 * @param
	 * @param
	 * @return
	 * @throws 
	 * @version v1.0
	 * @author zhaoxd
	 * @return 
	 * @date 2018年12月29日
	 *//*
	public Map<String,Object> findTZList()throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("select count(id) as num ,  c.EVENT_INFO,");
		sql.append("c.LINK_URL, c.MSG_INFO ");
		sql.append(" from SYS_EVENT_MESSAGE_INFO c ");
		sql.append("where c.EVENT_TYPE ='2' and c.EVENT_FLG='0' ");
		//人
		sql.append(" and RECEIVE_PERSON_ID = '" + InsertUserInfoUtil.getUserId() + "'  group by c.EVENT_INFO,c.LINK_URL,c.MSG_INFO  ");
		
		//获取返回数据总数
		Long totals =(long) 0;
		//分页
		List<Object[]> dcdbTaskInfoList = entityManager.createNativeQuery(sql.toString()).getResultList();
		List<SysEventMessageInfoDto> list2=new ArrayList<>();
		List<SysEventMessageInfoDto> list3=new ArrayList<>();
		for (Object[] obj : dcdbTaskInfoList) {
			SysEventMessageInfoDto sysEventMessageInfoDto=new SysEventMessageInfoDto();
			Long pid = obj[0] == null ? null : ((BigDecimal) obj[0]).longValue();
			totals+=pid;
			sysEventMessageInfoDto.setId(pid);
			sysEventMessageInfoDto.setEventInfo(obj[1] == null ? null : obj[1].toString());
			sysEventMessageInfoDto.setLinkUrl(obj[2] == null ? null : obj[2].toString());
			sysEventMessageInfoDto.setMsgInfo(obj[3] == null ? null : obj[3].toString());
			 sysEventMessageInfoDto.setEventInfo(sysEventMessageInfoDto.getEventInfo()+","+sysEventMessageInfoDto.getMsgInfo());
			list3.add(sysEventMessageInfoDto);
		}
		Map<String, Object> map = new HashMap<>();
		map.put("list", list3);
		map.put("totals", totals);
		return map;
	}
	*//** @Description 查询待办事件数量
	 * @return
	 * @throws
	 * @version v1.0
	 * @author zhaoxd
	 * @date 2019年2月15日
	 *//*
	public Integer queryWillDidNum() {
		Integer num=0;
	    num = sysEventMessageInfoRepository.findByEventFlgAndReceivePersonIdAndEventType(0,InsertUserInfoUtil.getUserId(),1).size();
	    return num;
	}

	*//** @Description 添加待办消息信息
	 * @param dto
	 * @throws
	 * @version v1.0
	 * @author zhaoxd
	 * @date 2019年2月15日
	 *//*
	@Transactional
	public  void insertEventMessage(SysEventMessageInfoDto dto)throws Exception {
		if(dto!=null){
					SysEventMessageInfo sysEventMessageInfo= LsBeanUtils.copyProperties(dto, SysEventMessageInfo.class);
					sysEventMessageInfo.setId(null);
					InsertUserInfoUtil.insertCreateInfo(sysEventMessageInfo);
					InsertUserInfoUtil.insertEditInfo(sysEventMessageInfo);
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					sysEventMessageInfo.setStartTime(formatter.format(DateUtil.getNowDate()));
					sysEventMessageInfo.setEventFlg(0);
					sysEventMessageInfo.setStartPersonId(InsertUserInfoUtil.getUserId());
					sysEventMessageInfo.setStartPersonName(InsertUserInfoUtil.getUserName());
					sysEventMessageInfo.setStartOrgId(InsertUserInfoUtil.getDeptId());
					sysEventMessageInfo.setStartOrgName(InsertUserInfoUtil.getDeptName());
					sysEventMessageInfoRepository.save(sysEventMessageInfo);
		}
	}

	*//** @Description 跳转到待办事项列表页面
	 * @param
	 * @throws
	 * @version v1.0
	 * @author zhaoxd
	 * @date 2019年2月15日
	 *//*
	public   String  goToEventPage(Long id)throws Exception {
		if(id!=null){
			SysEventMessageInfo sysEventMessageInfo=sysEventMessageInfoRepository.findById(id).get();
			if(sysEventMessageInfo!=null){
				if(sysEventMessageInfo.getLinkUrl()!=null&&sysEventMessageInfo.getLinkUrl().length()>0){
					//response.sendRedirect(sysEventMessageInfo.getLinkUrl()+"?id=" + sysEventMessageInfo.getEventId());
					return sysEventMessageInfo.getLinkUrl();
				}
			}
		}
		return "";
	}
	*//** @Description
	 * @param id
	 * @throws 
	 * @version v1.0
	 * @author zhaoxd
	 * @date 2019年2月15日
	 *//*
	public void editEventFlg(Long id)throws Exception {
		// TODO 自动生成的方法存根
		if(id!=null){
			List<SysEventMessageInfo> list = sysEventMessageInfoRepository.findByEventFlgAndEventIdAndReceivePersonId(0,id,InsertUserInfoUtil.getUserId());
			List<SysEventMessageInfo> list2=new ArrayList<>();
			for(int i=0;i<list.size();i++){
				SysEventMessageInfo sysEventMessageInfo=list.get(i);
					//改为已办
					sysEventMessageInfo.setEventFlg(1);
					InsertUserInfoUtil.insertEditInfo(sysEventMessageInfo);
					list2.add(sysEventMessageInfo);
			}
			sysEventMessageInfoRepository.saveAll(list2);
		}
	}

	*//**
	 * @Author XuYixuan
	 * @Description 根据数据ID修改所有待办状态
	 * @Date 2019/5/29 17:32
	 * @Param
	 * @Version 1.0
	 * @Return
	*//*
	public void editEventFlgByEventId(Long id)throws Exception {
		if(id!=null){
			List<SysEventMessageInfo> list = sysEventMessageInfoRepository.findByEventFlgAndEventId(0,id);
			List<SysEventMessageInfo> list2=new ArrayList<>();
			for(int i=0;i<list.size();i++){
				SysEventMessageInfo sysEventMessageInfo=list.get(i);
				//改为已办
				sysEventMessageInfo.setEventFlg(1);
				InsertUserInfoUtil.insertEditInfo(sysEventMessageInfo);
				list2.add(sysEventMessageInfo);
			}
			sysEventMessageInfoRepository.saveAll(list2);
		}
	}

	*//** @Description
	 * @param
	 * @throws 
	 * @version v1.0
	 * @author zhaoxd
	 * @date 2019年2月15日
	 *//*
	public void editEventFlgById(Long[] ids) throws Exception {
		// TODO 自动生成的方法存根
		if(ids!=null&&ids.length>0){
			List<SysEventMessageInfo> list=new ArrayList<>();
			for(int i=0;i<ids.length;i++){
				SysEventMessageInfo sysEventMessageInfo = sysEventMessageInfoRepository.findById(ids[i]).get();
					//改为已办或已读
					sysEventMessageInfo.setEventFlg(1);
					SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					sysEventMessageInfo.setDidTime(formatter.format(DateUtil.getNowDate()));
					sysEventMessageInfoRepository.save(sysEventMessageInfo);
					InsertUserInfoUtil.insertEditInfo(sysEventMessageInfo);
					list.add(sysEventMessageInfo);
			}
			sysEventMessageInfoRepository.saveAll(list);
		}
	}
	public  void insertEventMessages(List<SysEventMessageInfoDto> list) throws Exception {
		if(list!=null){
			List<SysEventMessageInfo> list2=new ArrayList<>();
			for(int i=0;i<list.size();i++){
				SysEventMessageInfo sysEventMessageInfo= LsBeanUtils.copyProperties(list.get(i), SysEventMessageInfo.class);
				sysEventMessageInfo.setId(null);
				InsertUserInfoUtil.insertCreateInfo(sysEventMessageInfo);
				InsertUserInfoUtil.insertEditInfo(sysEventMessageInfo);
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				sysEventMessageInfo.setStartTime(formatter.format(DateUtil.getNowDate()));
				sysEventMessageInfo.setStartPersonId(InsertUserInfoUtil.getUserId());
				sysEventMessageInfo.setEventFlg(0);
				sysEventMessageInfo.setStartPersonName(InsertUserInfoUtil.getUserName());
				sysEventMessageInfo.setStartOrgId(InsertUserInfoUtil.getDeptId());
				sysEventMessageInfo.setStartOrgName(InsertUserInfoUtil.getDeptName());
				list2.add(sysEventMessageInfo);
			}
			sysEventMessageInfoRepository.saveAll(list2);
		}
	}
	public  void systemInsertEventMessages(List<SysEventMessageInfoDto> list) throws Exception {
		if(list!=null){
			List<SysEventMessageInfo> list2=new ArrayList<>();
			for(int i=0;i<list.size();i++){
				SysEventMessageInfo sysEventMessageInfo= LsBeanUtils.copyProperties(list.get(i), SysEventMessageInfo.class);
				sysEventMessageInfo.setId(null);
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				sysEventMessageInfo.setStartTime(formatter.format(DateUtil.getNowDate()));
				sysEventMessageInfo.setStartPersonId("系统");
				sysEventMessageInfo.setEventFlg(0);
				sysEventMessageInfo.setCreateTime(DateUtil.getNowDate());
				sysEventMessageInfo.setEditTime(DateUtil.getNowDate());
				sysEventMessageInfo.setStartPersonName("系统");
				sysEventMessageInfo.setStartOrgName("系统");
				list2.add(sysEventMessageInfo);
			}
			sysEventMessageInfoRepository.saveAll(list2);
		}

	}
	@Transactional
	public  void insertEventMessage4Qyzc(SysEventMessageInfoDto dto)throws Exception {
		if(dto!=null){
			SysEventMessageInfo sysEventMessageInfo= LsBeanUtils.copyProperties(dto, SysEventMessageInfo.class);
			sysEventMessageInfo.setId(null);
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			sysEventMessageInfo.setStartTime(formatter.format(DateUtil.getNowDate()));
			sysEventMessageInfo.setEventFlg(0);
			sysEventMessageInfo.setStartPersonName("企业注册");
			sysEventMessageInfoRepository.save(sysEventMessageInfo);
		}
	}
	public void systemInsertEventMessage(SysEventMessageInfoDto dto) {
		if(dto!=null){
			SysEventMessageInfo sysEventMessageInfo= LsBeanUtils.copyProperties(dto, SysEventMessageInfo.class);
			sysEventMessageInfo.setId(null);
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			sysEventMessageInfo.setStartTime(formatter.format(DateUtil.getNowDate()));
			sysEventMessageInfo.setStartPersonId("系统");
			sysEventMessageInfo.setEventFlg(0);
			sysEventMessageInfo.setCreateTime(DateUtil.getNowDate());
			sysEventMessageInfo.setEditTime(DateUtil.getNowDate());
			sysEventMessageInfo.setStartPersonName("系统");
			sysEventMessageInfo.setStartOrgName("系统");
		}
	}
	public void editEventFlgByLinkUrl(SysEventMessageInfoDto dto) throws Exception {
		// TODO 自动生成的方法存根
		if(dto!=null&&dto.getLinkUrl()!=null&&dto.getLinkUrl().length()>0){
			List<SysEventMessageInfo> list=new ArrayList<>();
			List<SysEventMessageInfo> list2 = sysEventMessageInfoRepository.findByLinkUrlAndReceivePersonIdAndEventFlgAndEventType(dto.getLinkUrl(),InsertUserInfoUtil.getUserId(),0,2);
			//改为已办或已读
			for(int i=0;i<list2.size();i++){
				SysEventMessageInfo sysEventMessageInfo=list2.get(i);
				sysEventMessageInfo.setEventFlg(1);
				sysEventMessageInfoRepository.save(sysEventMessageInfo);
				InsertUserInfoUtil.insertEditInfo(sysEventMessageInfo);
				list.add(sysEventMessageInfo);
			}
			sysEventMessageInfoRepository.saveAll(list);
		}
	}*/


}
