package com.jpsoft.shinestar.modules.business.service.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import javax.annotation.Resource;

import cn.hutool.core.date.DateUtil;
import com.jpsoft.shinestar.config.WxConfig;
import com.jpsoft.shinestar.modules.base.entity.ApprovalConfig;
import com.jpsoft.shinestar.modules.base.entity.CompanyInfo;
import com.jpsoft.shinestar.modules.base.entity.PersonInfo;
import com.jpsoft.shinestar.modules.base.entity.PersonPopedom;
import com.jpsoft.shinestar.modules.base.service.ApprovalConfigService;
import com.jpsoft.shinestar.modules.base.service.CompanyInfoService;
import com.jpsoft.shinestar.modules.base.service.PersonInfoService;
import com.jpsoft.shinestar.modules.base.service.PersonPopedomService;
import com.jpsoft.shinestar.modules.business.dto.UpdatePersonAttendanceDTO;
import com.jpsoft.shinestar.modules.common.utils.JwtUtil2;
import com.jpsoft.shinestar.modules.common.utils.WechatMessageUtil;
import com.jpsoft.shinestar.modules.workflow.entity.ProcinstActUser;
import com.jpsoft.shinestar.modules.workflow.entity.ProcinstActivity;
import com.jpsoft.shinestar.modules.workflow.service.ProcinstActUserService;
import com.jpsoft.shinestar.modules.workflow.service.ProcinstActivityService;
import com.jpsoft.shinestar.modules.workflow.service.ProcinstService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.Hours;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.business.dao.YearRequestForLeaveInfoDAO;
import com.jpsoft.shinestar.modules.business.entity.YearRequestForLeaveInfo;
import com.jpsoft.shinestar.modules.business.service.YearRequestForLeaveInfoService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="yearRequestForLeaveInfoService")
@Slf4j
public class YearRequestForLeaveInfoServiceImpl implements YearRequestForLeaveInfoService {
	@Resource(name="yearRequestForLeaveInfoDAO")
	private YearRequestForLeaveInfoDAO yearRequestForLeaveInfoDAO;

	@Autowired
	private ProcinstService procinstService;

	@Autowired
	private ProcinstActivityService procinstActivityService;

	@Autowired
	private ProcinstActUserService procinstActUserService;

	@Autowired
	private PersonInfoService personInfoService;

	@Autowired
	private PersonPopedomService personPopedomService;

	@Autowired
	private ApprovalConfigService approvalConfigService;

	@Value("${jwt.secret}")
	private String jwtSecret;

	@Autowired
	private WxConfig wxConfig;

	@Autowired
	private CompanyInfoService companyInfoService;

	@Autowired
	RabbitTemplate rabbitTemplate;


	@Override
	public YearRequestForLeaveInfo get(String id) {
		// TODO Auto-generated method stub
		return yearRequestForLeaveInfoDAO.get(id);
	}

	@Override
	public int insert(YearRequestForLeaveInfo model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());
		
		return yearRequestForLeaveInfoDAO.insert(model);
	}

	@Override
	public int update(YearRequestForLeaveInfo model) {
		// TODO Auto-generated method stub
		return yearRequestForLeaveInfoDAO.update(model);		
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return yearRequestForLeaveInfoDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = yearRequestForLeaveInfoDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<YearRequestForLeaveInfo> list() {
		// TODO Auto-generated method stub
		return yearRequestForLeaveInfoDAO.list();
	}

    @Override
    public List<YearRequestForLeaveInfo> findByPersonIdAndDate(Long personId, Date attendanceDate) {
        return yearRequestForLeaveInfoDAO.findByPersonIdAndDate(personId, attendanceDate);
    }
		
	@Override
	public Page<YearRequestForLeaveInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<YearRequestForLeaveInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            yearRequestForLeaveInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public Page<YearRequestForLeaveInfo> pageMobileSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
		Page<YearRequestForLeaveInfo> page = PageHelper.startPage(pageNumber, pageSize, count).doSelectPage(() -> {
			yearRequestForLeaveInfoDAO.mobileSearch(searchParams, sortList);
		});
		return page;
	}

    @Override
    public BigDecimal sumDaysByPersonIdAndTimeRange(Long personId, Date startDate, Date endDate){
        //查询时间段与出差交集部分
        List<YearRequestForLeaveInfo> boList = yearRequestForLeaveInfoDAO.findByPersonIdAndSEDate(personId,startDate,endDate);
        BigDecimal totalAttendanceNum = BigDecimal.ZERO;

        for(YearRequestForLeaveInfo yearRequestForLeaveInfo : boList){
//            if(bo.getEstimatedTime() != null) {
//                BigDecimal et = new BigDecimal(bo.getEstimatedTime());
//                totalAttendanceNum = totalAttendanceNum.add(et);
//            }
            //查询交集部分小时数
            Date maxStartDate = yearRequestForLeaveInfo.getStartTime().compareTo(startDate)>0 ? yearRequestForLeaveInfo.getStartTime() : startDate;
            Date minEndDate = yearRequestForLeaveInfo.getEndTime().compareTo(endDate)<0 ? yearRequestForLeaveInfo.getEndTime() : endDate;

            int hours = Hours.hoursBetween(new DateTime(maxStartDate),new DateTime(minEndDate)).getHours();
            BigDecimal days = new BigDecimal(hours).divide(new BigDecimal(24),1, RoundingMode.HALF_UP);

            totalAttendanceNum = totalAttendanceNum.add(days);
        }

        return totalAttendanceNum;
    }


	@Override
	public void logic(YearRequestForLeaveInfo yearRequestForLeaveInfo) throws Exception {
		//更新人员工作状态
		updatePersonWorkStatus(yearRequestForLeaveInfo);

		Date now = new Date();
		if (yearRequestForLeaveInfo.getStartTime().before(now)) {
			PersonPopedom personPopedom = personPopedomService.get(yearRequestForLeaveInfo.getPersonPopedomId());
			PersonInfo personInfo = personInfoService.get(personPopedom.getPersonId());

			UpdatePersonAttendanceDTO updatePersonAttendanceDTO = new UpdatePersonAttendanceDTO(
					personInfo.getId(), yearRequestForLeaveInfo.getStartTime(),yearRequestForLeaveInfo.getEndTime());

			rabbitTemplate.convertAndSend("updatePersonAttendanceQueue", updatePersonAttendanceDTO);
		}
	}

	@Override
	public void updatePersonWorkStatus(YearRequestForLeaveInfo yearRequestForLeaveInfo) {
		try{
			PersonPopedom personPopedom = personPopedomService.get(yearRequestForLeaveInfo.getPersonPopedomId());
			PersonInfo personInfo = personInfoService.get(personPopedom.getPersonId());

			Date now = new Date();

			//如果年假开始时间<=当前时间，说明是补年假记录，可能正在年假
			if (yearRequestForLeaveInfo.getStartTime().compareTo(now) <=0){
				personInfo.setWorkStatus("7");
				personInfoService.update(personInfo);
			}
			else {
				//如果年假开始开始时间>当前时间，则延时修改状态
				long millisecond = DateUtil.betweenMs(now,yearRequestForLeaveInfo.getStartTime());

				log.warn("创建延时队列修改工作状态，id："+yearRequestForLeaveInfo.getId());

				rabbitTemplate.convertAndSend("yearRequestForLeaveDelayExchange", "yearRequestForLeaveSubmit",
						yearRequestForLeaveInfo.getId(), (message)->{
							message.getMessageProperties().setHeader("x-delay",millisecond);
							return message;
						});
			}

			if(yearRequestForLeaveInfo.getEndTime()!=null) {
				//如果年假结束时间<=当前时间，说明年假结束
				if (yearRequestForLeaveInfo.getEndTime().compareTo(now) <= 0) {
					personInfo.setWorkStatus("1");
					personInfoService.update(personInfo);
				} else {
					//如果年假结束时间>当前时间，则延时修改状态
					long millisecond = DateUtil.betweenMs(now, yearRequestForLeaveInfo.getEndTime())+60000;

					log.warn("创建延时队列修改工作状态，id：" + yearRequestForLeaveInfo.getId());

					rabbitTemplate.convertAndSend("yearRequestForLeaveDelayExchange", "yearRequestForLeaveSubmit",
							yearRequestForLeaveInfo.getId(), (message) -> {
								message.getMessageProperties().setHeader("x-delay", millisecond);
								return message;
							});
				}
			}
		}catch (Exception ex){
			log.error(ex.getMessage(),ex);
		}
	}


	@Override
	public String leaveSubmit(PersonPopedom personPopedom, String startTime, String endTime, String startTimeQuantum, String endTimeQuantum, String imageUrl, String reason, String days, String formId, String activity, String draft, String id) throws Exception {
		try {
			YearRequestForLeaveInfo yearRequestForLeaveInfo = null;
			if (StringUtils.isNotEmpty(id)) {
				yearRequestForLeaveInfo = yearRequestForLeaveInfoDAO.get(id);

			} else {
				yearRequestForLeaveInfo = new YearRequestForLeaveInfo();
				yearRequestForLeaveInfo.setId(UUID.randomUUID().toString());
				yearRequestForLeaveInfo.setDelFlag(false);
			}

			String startTimeStr = DateUtil.format(DateUtil.parse(startTime), "yyyy-MM-dd");
			String endTimeStr = DateUtil.format(DateUtil.parse(endTime), "yyyy-MM-dd");
			if ("0".equals(startTimeQuantum)) {
				startTimeStr = startTimeStr + " " + "00:00:00";
			}
			if ("1".equals(startTimeQuantum)) {
				startTimeStr = startTimeStr + " " + "12:00:00";
			}
			if ("0".equals(endTimeQuantum)) {
				endTimeStr = endTimeStr + " " + "12:00:00";
			}
			if ("1".equals(endTimeQuantum)) {
				endTimeStr = endTimeStr + " " + "23:59:59";
			}
			yearRequestForLeaveInfo.setStartTime(DateUtil.parse(startTimeStr, "yyyy-MM-dd HH:mm:ss"));
			/*if (days.contains(".")){
				Integer n  = days.indexOf(".");
				String intDays = days.substring(0,n);
				requestForLeaveInfo.setEndTime(DateUtil.offsetDay(requestForLeaveInfo.getStartTime(),Integer.parseInt(intDays)));
				requestForLeaveInfo.setEndTime(DateUtil.offsetHour(requestForLeaveInfo.getStartTime(),12));
			}else {
				requestForLeaveInfo.setEndTime(DateUtil.offsetDay(requestForLeaveInfo.getStartTime(),Integer.parseInt(days)));
			}*/


			yearRequestForLeaveInfo.setEndTime(DateUtil.parse(endTimeStr, "yyyy-MM-dd HH:mm:ss"));
			yearRequestForLeaveInfo.setImageUrl(imageUrl);
			yearRequestForLeaveInfo.setReason(reason);
			yearRequestForLeaveInfo.setPersonId(personPopedom.getPersonId());
			yearRequestForLeaveInfo.setPersonPopedomId(personPopedom.getId());
			yearRequestForLeaveInfo.setCreateTime(new Date());
			yearRequestForLeaveInfo.setStatus(-99);

			yearRequestForLeaveInfo.setStartTimeQuantum(startTimeQuantum);
			yearRequestForLeaveInfo.setEndTimeQuantum(endTimeQuantum);
			yearRequestForLeaveInfo.setDays(days);
			if (StringUtils.isNotEmpty(id)) {

				update(yearRequestForLeaveInfo);
			} else {
				insert(yearRequestForLeaveInfo);
			}

			String ide = yearRequestForLeaveInfo.getId();

			if ("1".equals(draft)) {
				Map<String, Object> conditions = new HashMap<>();
				conditions.put("day", Double.valueOf(days));

				String procInstId = procinstService.addProcInst(ide, "年假", formId, personPopedom, activity, null, null);

				yearRequestForLeaveInfo.setProcinstId(procInstId);
				yearRequestForLeaveInfo.setStatus(0);
				update(yearRequestForLeaveInfo);


				ProcinstActivity procinstActivity = procinstActivityService.findByActivityIndexAndProcinstId(1, procInstId);


				if (procinstActivity != null) {

					List<ProcinstActUser> procinstActUserList = procinstActUserService.findByProcinstActivityIdActionType(procinstActivity.getId(), "0", "1");
					if (procinstActUserList.size() > 0) {

						new Thread(() -> {
							for (ProcinstActUser procinstActUser : procinstActUserList) {
								try {
									PersonInfo personInfo = personInfoService.get(Long.parseLong(procinstActUser.getUserId()));

									//提交人
									PersonInfo personInfo1 = personInfoService.get(personPopedom.getPersonId());
									String accessToken = JwtUtil2.createToken(jwtSecret, personInfo.getId() + "", DateTime.now().plusHours(30 * 24).toDate());
									WechatMessageUtil.sendEvenMessage(personInfo.getOpenId(), "有一条新的请年假信息待审核", personInfo1.getName(), com.jpsoft.shinestar.modules.common.utils.StringUtils.getApprovalNo(), "前往处理", wxConfig.getPortalUrl() + "xsy/approval/infosp?id=" + ide + "&procinstActUserId=" + procinstActUser.getId() + "&formId=" + formId + "&token=" + accessToken, wxConfig.getAppId(), wxConfig.getAppSecret());
								} catch (Exception ex) {
									ex.printStackTrace();
								}

							}
						}).start();
					}
				}
			}

			return ide;

		} catch (Exception ex) {
			throw new Exception(ex.getMessage());
		}
	}


	@Override
	public void approvalRequestForLeave(PersonInfo personInfo, String ids, String approvalOpinions, String approvalExplain, int status) throws Exception {

		//审核人
		PersonPopedom personPopedom = personPopedomService.get(personInfo.getPopedom());
		List<String> idList = Arrays.asList(ids.split(","));
		if (idList.size() > 0) {
			for (String id : idList) {
				YearRequestForLeaveInfo yearRequestForLeaveInfo = get(id);
				if (yearRequestForLeaveInfo.getStatus() == 0) {
					//申请人
					PersonPopedom personPopedom1 = personPopedomService.get(yearRequestForLeaveInfo.getPersonPopedomId());
					PersonInfo personInfo1 = personInfoService.get(personPopedom1.getPersonId());

					if (!yearRequestForLeaveInfo.getApprovedPersonPopedomId().equals(personInfo.getPopedom())) {
						throw new Exception("无权审核");
					}
					String approvalPersonIdStr = yearRequestForLeaveInfo.getApprovalPersonIdStr();
					String approvalStatusStr = yearRequestForLeaveInfo.getApprovalStatusStr();
					String approvalTimeStr = yearRequestForLeaveInfo.getApprovalTimeStr();
					String approvalContentStr = yearRequestForLeaveInfo.getApprovalContentStr();


					//同意
					if (status == 1) {

						List<PersonPopedom> personPopedomList = new ArrayList<>();

						String companyId = "";
						//申请人的公司
						CompanyInfo companyInfo = companyInfoService.get(personPopedom1.getCompanyId());

						if (!"1".equals(companyInfo.getUnitType())) {

							CompanyInfo parent = null;
							int loopNum = 10;
							int zIndex = 0;
							if (org.apache.commons.lang3.StringUtils.isNotEmpty(companyInfo.getParentId())) {
								parent = companyInfoService.get(companyInfo.getParentId());
							}
							while (parent != null && zIndex < loopNum) {
								ApprovalConfig approvalConfig = approvalConfigService.findByCompanyIdAndType(companyInfo.getId(), "7");
								if (approvalConfig != null) {
									companyId = companyInfo.getId();
									break;
								} else if (org.apache.commons.lang3.StringUtils.isBlank(companyInfo.getParentId())) {
									break;
								} else {
									parent = companyInfoService.get(parent.getParentId());
									companyInfo = companyInfoService.get(companyInfo.getParentId());
									zIndex++;
								}
							}

							/*CompanyInfo parent = null;
							int loopNum = 10;
							int zIndex = 0;

							if (StringUtils.isNotEmpty(companyInfo.getParentId())) {
								parent = companyInfoService.get(companyInfo.getParentId());
							}
							while (parent != null && zIndex < loopNum) {

								if ("1".equals(parent.getUnitType())) {
									//如果是单位类型是公司或没有上级单位，则不再往上级查找
									companyId = parent.getId();
									break;
								}
								else if (StringUtils.isEmpty(companyInfo.getParentId())){
									break;
								}
								else {
									parent = companyInfoService.get(parent.getParentId());
									zIndex++;
								}
							}*/


						} else {
							companyId = companyInfo.getId();
						}

						//默认审核层级
						int level = 2;

						if (StringUtils.isNotBlank(companyId)) {

							ApprovalConfig approvalConfig = approvalConfigService.findByCompanyIdAndType(companyId, "7");
							if (approvalConfig != null) {
								BigDecimal days = new BigDecimal(approvalConfig.getDays());
								if (days.compareTo(new BigDecimal(yearRequestForLeaveInfo.getDays())) > 0) {
									level = Integer.valueOf(approvalConfig.getLevel());
								} else {
									level = 10;
								}
							} else {
								if (new BigDecimal(3).compareTo(new BigDecimal(yearRequestForLeaveInfo.getDays())) <= 0) {
									level = 10;
								}
							}

						}

						//计算当前审核的是第几级审批
						int nowLevel = 1;
						if (StringUtils.isNotBlank(approvalPersonIdStr)) {
							nowLevel = nowLevel + Arrays.asList(approvalPersonIdStr.split(",")).size();
						}
						//判断已审核人总数和需要审核级数
						if (nowLevel < level) {
							List<PersonPopedom> dataList = personPopedomService.findApprovalList(personInfo, "4", null, null);
							if (dataList.size() > 0) {
								personPopedomList.add(dataList.get(0));
							}

						}

						//判断审批人数量,审批人数据为0，审批流程走完
						if (personPopedomList.size() == 0) {
							yearRequestForLeaveInfo.setApprovedTime(new Date());
							yearRequestForLeaveInfo.setStatus(status);
							yearRequestForLeaveInfo.setApprovalOpinions(approvalOpinions);
							yearRequestForLeaveInfo.setApprovalExplain(approvalExplain);
							yearRequestForLeaveInfo.setUpdateBy(personInfo.getPopedom());
							yearRequestForLeaveInfo.setUpdateTime(new Date());
							update(yearRequestForLeaveInfo);

//							int a1 = "0".equals(yearRequestForLeaveInfo.getStartTimeQuantum()) ? 0 : 43200000;
//							int a2 = "0".equals(yearRequestForLeaveInfo.getEndTimeQuantum()) ? 43200000 : 86400000;
//							;
//
//							Date startLong = new Date(yearRequestForLeaveInfo.getStartTime().getTime() + a1);
//							Date endLong = new Date(yearRequestForLeaveInfo.getEndTime().getTime() + a2);
//
//							//时间符合为休假，
//
//							String initStatus = personInfo1.getWorkStatus();
//							if (startLong.getTime() < new Date().getTime() && endLong.getTime() > new Date().getTime()) {
//								personInfo1.setWorkStatus("4");//请假
//								personInfo1.setUpdateBy(personPopedom.getPersonId().toString());
//								personInfo1.setUpdateTime(new Date());
//								personInfoService.update(personInfo1);
//							}
//
//							if (personInfo1.getWorkStatus() == null) {
//								personInfo1.setWorkStatus("1");
//								initStatus = "1";
//							}
//							//休假，还没开始
//							if (startLong.getTime() > new Date().getTime()) {
//
//								//防止连续请假，造成的时间重叠
//								Long milliseconds = startLong.getTime() - new Date().getTime() + 5000;
//								String p = "A_" + personInfo1.getId() + "_" + personInfo1.getWorkStatus() + "_" + personPopedom.getPersonId();
//								rabbitTemplate.convertAndSend("updateWorkStatusExchange", "updateWorkStatus", p, (message) -> {
//									//延时单位毫秒
//									message.getMessageProperties().setHeader("x-delay", milliseconds);
//									return message;
//								});
//							}
//							//休假，结束
//							if (endLong.getTime() > new Date().getTime()) {
//								String p = "B_" + personInfo1.getId() + "_" + initStatus + "_" + personPopedom.getPersonId();
//								//防止连续请假，造成的时间重叠
//								Long milliseconds = endLong.getTime() - new Date().getTime() - 5000;
//
//								rabbitTemplate.convertAndSend("updateWorkStatusExchange", "updateWorkStatus", p, (message) -> {
//									//延时单位毫秒
//									message.getMessageProperties().setHeader("x-delay", milliseconds);
//									return message;
//								});
//							}


						}
						//审批人数据不为0
						else {
							PersonPopedom personPopedom2 = personPopedomList.get(0);
							if (StringUtils.isNotBlank(approvalPersonIdStr)) {
								yearRequestForLeaveInfo.setApprovalPersonIdStr(approvalPersonIdStr + "," + yearRequestForLeaveInfo.getApprovedPersonPopedomId());
								yearRequestForLeaveInfo.setApprovalStatusStr(approvalStatusStr + "," + status);
								yearRequestForLeaveInfo.setApprovalTimeStr(approvalTimeStr + "," + DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
								yearRequestForLeaveInfo.setApprovalContentStr(approvalContentStr + "," + approvalExplain);
							} else {
								yearRequestForLeaveInfo.setApprovalPersonIdStr(yearRequestForLeaveInfo.getApprovedPersonPopedomId());
								yearRequestForLeaveInfo.setApprovalStatusStr(String.valueOf(status));
								yearRequestForLeaveInfo.setApprovalTimeStr(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
								yearRequestForLeaveInfo.setApprovalContentStr(approvalExplain);
							}

							yearRequestForLeaveInfo.setApprovedPersonPopedomId(personPopedom2.getId());
							yearRequestForLeaveInfo.setStatus(0);
							yearRequestForLeaveInfo.setApprovalOpinions("");
							yearRequestForLeaveInfo.setApprovedTime(null);
							update(yearRequestForLeaveInfo);

							new Thread(() -> {
								PersonInfo approvalPerson = personInfoService.get(personPopedom2.getPersonId());

								String typeN = "年假";
								String url = "master/attendance/verifyLeaveInfo?id=";

								String accessToken = JwtUtil2.createToken(jwtSecret, approvalPerson.getId() + "", DateTime.now().plusHours(30 * 24).toDate());
								WechatMessageUtil.sendEvenMessage(approvalPerson.getOpenId(), "有一条新的" + typeN + "信息待审核", personInfo1.getName(), yearRequestForLeaveInfo.getId().substring(0, 5), "前往处理", wxConfig.getPortalUrl() + url + yearRequestForLeaveInfo.getId() + "&exchange=1&role_id=" + personPopedom2.getId() + "&token=" + accessToken, wxConfig.getAppId(), wxConfig.getAppSecret());

							}).start();


						}

						//     }


					}
					//拒绝
					if (status == 2) {
						yearRequestForLeaveInfo.setApprovedTime(new Date());
						yearRequestForLeaveInfo.setStatus(status);
						yearRequestForLeaveInfo.setApprovalOpinions(approvalOpinions);
						yearRequestForLeaveInfo.setApprovalExplain(approvalExplain);
						yearRequestForLeaveInfo.setUpdateBy(personPopedom.getId());
						yearRequestForLeaveInfo.setUpdateTime(new Date());
						update(yearRequestForLeaveInfo);

					}

					//通知申请人

					if (yearRequestForLeaveInfo.getStatus() != 0) {
						new Thread(() -> {
							String firstMessage = "";
							String getstatus = "";

							if (1 == status) {
								firstMessage = "审核通过";
								getstatus = "1";
								//延时队列处理人员工作状态
								updatePersonWorkStatus(yearRequestForLeaveInfo);

							} else {
								firstMessage = "审核拒绝";
								getstatus = "2";
							}


							String url = "master/attendance/leaveInfo";


							String accessToken = JwtUtil2.createToken(jwtSecret, personInfo1.getId() + "", DateTime.now().plusHours(30 * 24).toDate());
							WechatMessageUtil.sendExamine(personInfo1.getOpenId(), firstMessage, personInfo1.getName(), getstatus, firstMessage, "请假", "前往查看", wxConfig.getPortalUrl() + url + "?id=" + yearRequestForLeaveInfo.getId() + "&exchange=1&role_id=" + personPopedom1.getId() + "&token=" + accessToken, wxConfig.getAppId(), wxConfig.getAppSecret());
						}).start();


					}
				}
			}
		}
	}
}