package com.prolog.rdc.tms.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import com.codingapi.tx.annotation.TxTransaction;
import com.prolog.framework.core.exception.PrologException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.prolog.common.util.ToolKits;
import com.prolog.cs.platform.power.model.enterprise.User;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.Order;
import com.prolog.framework.core.restriction.Restriction;
import com.prolog.framework.core.restriction.Restrictions;
import com.prolog.framework.dao.util.PageUtils;
import com.prolog.product.core.framework.entity.UserEntity;
import com.prolog.product.core.framework.util.PlgFxUsrUtils;
import com.prolog.rdc.tms.constant.DataDictionaryConstant;
import com.prolog.rdc.tms.constant.SeriaNnumberConstant;
import com.prolog.rdc.tms.dao.mapper.TmsApprovalBusinessDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsApprovalBusinessLogMapper;
import com.prolog.rdc.tms.dao.mapper.TmsApprovalBusinessMapper;
import com.prolog.rdc.tms.dao.mapper.TmsApprovalConditionMapper;
import com.prolog.rdc.tms.dao.mapper.TmsApprovalHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsApprovalNdApproveMapper;
import com.prolog.rdc.tms.dao.mapper.TmsApprovalNodeMapper;
import com.prolog.rdc.tms.model.dto.ApplyApprovalQueryDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.PendingApprovalQueryDTO;
import com.prolog.rdc.tms.model.dto.basicData.ApprovalLogDTO;
import com.prolog.rdc.tms.model.dto.basicData.ApprovalNodeSelDTO;
import com.prolog.rdc.tms.model.entity.line.TmsApprovalBusDetailModel;
import com.prolog.rdc.tms.model.entity.line.TmsApprovalBusLogModel;
import com.prolog.rdc.tms.model.entity.line.TmsApprovalBusinessModel;
import com.prolog.rdc.tms.model.entity.line.TmsApprovalCndModel;
import com.prolog.rdc.tms.model.entity.line.TmsApprovalHeaderModel;
import com.prolog.rdc.tms.model.entity.line.TmsApprovalNdApproverModel;
import com.prolog.rdc.tms.model.entity.line.TmsApprovalNodeModel;
import com.prolog.rdc.tms.model.vo.ApplyApprovalVO;
import com.prolog.rdc.tms.model.vo.ApprovalBusLogSaveVO;
import com.prolog.rdc.tms.model.vo.ApprovalBusinessNodeVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalOpenVO;
import com.prolog.rdc.tms.rmi.feign.UserFeign;
import com.prolog.rdc.tms.service.ApprovalBusinessService;
import com.prolog.rdc.tms.service.SysCodeengineService;
import com.prolog.rdc.tms.service.SysRefdatadService;
import com.prolog.rdc.tms.util.PublicMethods;

import cn.hutool.core.date.DateUtil;

/**
 * 审批业务实现层
 *
 * @author :lhb
 * @version :1.0.0
 * @className :SysCodeengineServiceImpl
 * @creationTime :2022/05/07
 * @description :
 * @modifier :
 * @modifyTime :
 * @reviseRemarks:
 */
@Service
@Slf4j
public class ApprovalBusinessServiceImpl implements ApprovalBusinessService {

	@Autowired
	private TmsApprovalBusinessLogMapper tmsApprovalBusinessLogMapper;

	@Autowired
	private SysCodeengineService sysCodeengineService;

	@Autowired
	private TmsApprovalHeaderMapper tmsApprovalHeaderMapper;

	@Autowired
	private TmsApprovalNodeMapper tmsApprovalNodeMapper;

	@Autowired
	private TmsApprovalNdApproveMapper tmsApprovalNdApproveMapper;

	@Autowired
	private TmsApprovalBusinessMapper tmsApprovalBusinessMapper;

	@Autowired
	private TmsApprovalBusinessDetailMapper tmsApprovalBusinessDetailMapper;

	@Autowired
	private SysRefdatadService sysRefdatadService;

	@Autowired
	private UserFeign userTmsResource;

	@Autowired
	private TmsApprovalConditionMapper tmsApprovalConditionMapper;

	/**
	 * 是否开启审批流程
	 *
	 * @param approvalOpenVO
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Boolean approvalOpen(ApprovalOpenVO approvalOpenVO) {
		ToolKits.isParamNull(approvalOpenVO, "是否开启审批流程请求参数不为空");
		ToolKits.isParamNull(approvalOpenVO.getApprovalFlowType(), "审批流程类型不为空");
		ToolKits.isParamNull(approvalOpenVO.getApprovalObjectId(), "审批对象ID不为空");
		ToolKits.isParamNull(approvalOpenVO.getApprovalObjectCode(), "审批对象编码不为空");
		ToolKits.isParamNull(approvalOpenVO.getApprovalObjectName(), "审批对象名称不为空");
		ToolKits.isParamNull(approvalOpenVO.getInitiatedUserId(), "发起人ID不为空");
		ToolKits.isParamNull(approvalOpenVO.getInitiatedUserName(), "发起人名称不为空");
		// 人员权限
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 审批对象是否已经开启过审批流
		Criteria criteriaApprovalBusiness = Criteria.forClass(TmsApprovalBusinessModel.class);
		Restriction r1 = Restrictions.eq(TmsApprovalBusinessModel::getApprovalObjectId, approvalOpenVO.getApprovalObjectId());
		Restriction r2 = Restrictions.eq(TmsApprovalBusinessModel::getApprovalFlowType, approvalOpenVO.getApprovalFlowType());
		Restriction r3 = Restrictions.eq(TmsApprovalBusinessModel::getEnterpriseId, user.getEnterpriseId());
		criteriaApprovalBusiness.setRestriction(Restrictions.and(r1, r2,r3));
		List<TmsApprovalBusinessModel> headerModels = tmsApprovalBusinessMapper.findByCriteria(criteriaApprovalBusiness);
		if (ToolKits.isNotEmpty(headerModels) && 0 < headerModels.size()) {
			log.info("审批对象{}的审批流已经开启了",approvalOpenVO.getApprovalObjectCode());
			throw new PrologException(approvalOpenVO.getApprovalObjectCode()+"的审批已经开启了");
		}

		// 适配审批流
		TmsApprovalHeaderModel tmsApprovalHeaderModel = matchApproval(approvalOpenVO, user);
		if (ToolKits.isEmpty(tmsApprovalHeaderModel)) {
			return false;
		}

		// 需要开启审批流
		// 流程节点明细查询
		Criteria criteriaNode = Criteria.forClass(TmsApprovalNodeModel.class);
		Restriction r7 = Restrictions.eq("approvalId", tmsApprovalHeaderModel.getApprovalId());
		Restriction r8 = Restrictions.eq("status", DataDictionaryConstant.NODE_STATUS_ENABLE);
		Restriction r9 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteriaNode.setRestriction(Restrictions.and(r7, r8, r9));
		criteriaNode.setOrder(Order.newInstance().asc(new String[] { "nodeOrder" }));
		List<TmsApprovalNodeModel> tmsApprovalNodeModels = tmsApprovalNodeMapper.findByCriteria(criteriaNode);

		if (ToolKits.isEmpty(tmsApprovalNodeModels) || tmsApprovalNodeModels.size() == 0) {
			return false;
		}
		// 流程节点明细审批者表查询
		String nextNodeRoleIds = "";
		String nextNoodeRoleNames = "";
		String nextNoodeUserIds = "";
		String nextNoodeUserNames = "";

		// 流程业务主表ID
		String businessId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_APPROVAL_BUSINESS_ID, "L");
		ToolKits.isParamNull(businessId, "流程业务主表ID生成失败");
		// 当前日期
		Date date = DateUtil.date();
		for (TmsApprovalNodeModel nodeModel : tmsApprovalNodeModels) {
			// 审批角色 用户
			String currentNodeRoleIds = "";
			String currentNoodeRoleNames = "";
			String currentNoodeUserIds = "";
			String currentNoodeUserNames = "";

			Criteria criteriaNodeApprover = Criteria.forClass(TmsApprovalNdApproverModel.class);
			Restriction r10 = Restrictions.eq("approvalId", tmsApprovalHeaderModel.getApprovalId());
			Restriction r11 = Restrictions.eq("approvalNodeId", nodeModel.getNodeId());
			Restriction r12 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaNodeApprover.setRestriction(Restrictions.and(r10, r11, r12));
			List<TmsApprovalNdApproverModel> nodeApproverModels = tmsApprovalNdApproveMapper.findByCriteria(criteriaNodeApprover);
			if (nodeApproverModels.size() == 0) {
				return false;
			}
			Set<String> userIds = new HashSet<>();
			Set<String> userNames = new HashSet<>();
			Set<String> roleIds = new HashSet<>();
			Set<String> roleNames = new HashSet<>();
			for (TmsApprovalNdApproverModel approver : nodeApproverModels) {
				if (nodeModel.getNodeApproverType().equals(DataDictionaryConstant.NODE_APPROVER_TYPE_ROLE)) {
					// role
					roleIds.add(String.valueOf(approver.getApproverRoleId()));
					roleNames.add(approver.getApproverRoleName());
					List<User> data1 = Lists.newArrayList();
					RestMessage<List<User>> Users = userTmsResource.usersByRoleId(null, null, String.valueOf(approver.getApproverRoleId()));
					if (!Users.isSuccess()) {
						throw new RuntimeException("审批角色【" + approver.getApproverRoleName() + "】下，没有用户!");
					} else {
						data1 = Users.getData();
					}
					for (User user1 : data1) {
						userIds.add(user1.getId());
						userNames.add(user1.getNickname());
					}

				} else {
					// user
					userIds.add(String.valueOf(approver.getApproverUserId()));
					userNames.add(approver.getApproverUserName());
				}
			}

			// 流程业务明细表的做成
			TmsApprovalBusDetailModel businessDetailModel = new TmsApprovalBusDetailModel();
			// 流程业务主表ID
			String businessDetailId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_APPROVAL_BUSINESS_DETAIL_ID, "L");
			ToolKits.isParamNull(businessDetailId, "流程业务明细表ID生成失败");
			businessDetailModel.setId(Long.valueOf(businessDetailId));
			// 审批业务ID
			businessDetailModel.setApprovalBusinessId(Long.valueOf(businessId));
			// 审批流程ID
			businessDetailModel.setApprovalId(nodeModel.getApprovalId());
			// 审批流程节点ID
			businessDetailModel.setApprovalNodeId(nodeModel.getNodeId());
			// 审批节点顺序
			businessDetailModel.setApprovalNodeOrder(nodeModel.getNodeOrder());
			// 节点审批者类型 1 角色 2 用户
			businessDetailModel.setNodeApproverType(nodeModel.getNodeApproverType());
			// 审批方式 1 会签 2 或签
			businessDetailModel.setNodeApprovalType(nodeModel.getNodeApprovalType());
			// 状态 1待审批
			businessDetailModel.setStatus(DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_PENDING);
			if (nodeModel.getNodeApproverType().equals(DataDictionaryConstant.NODE_APPROVER_TYPE_ROLE)) {
				currentNodeRoleIds = roleIds.stream().collect(Collectors.joining(","));
				currentNoodeRoleNames = roleNames.stream().collect(Collectors.joining(","));
				currentNoodeUserIds = userIds.stream().collect(Collectors.joining(","));
				currentNoodeUserNames = userNames.stream().collect(Collectors.joining(","));
			} else {
				currentNoodeUserIds = userIds.stream().collect(Collectors.joining(","));
				currentNoodeUserNames = userNames.stream().collect(Collectors.joining(","));
			}
			businessDetailModel.setApproverRoleId(currentNodeRoleIds);
			businessDetailModel.setApproverRoleName(currentNoodeRoleNames);
			businessDetailModel.setApproverUserId(currentNoodeUserIds);
			businessDetailModel.setApproverUserName(currentNoodeUserNames);

			businessDetailModel.setCreatetime(date);
			businessDetailModel.setCreateperson(user.getNickname());
			businessDetailModel.setUpdatetime(date);
			businessDetailModel.setUpdateperson(user.getNickname());
			businessDetailModel.setEnterpriseId(user.getEnterpriseId());
			businessDetailModel.setEnterpriseName(user.getEnterpriseName());
			tmsApprovalBusinessDetailMapper.save(businessDetailModel);

			if (nodeModel.getNodeOrder() == 1) {
				if (nodeModel.getNodeApproverType().equals(DataDictionaryConstant.NODE_APPROVER_TYPE_ROLE)) {
					nextNodeRoleIds = roleIds.stream().collect(Collectors.joining(","));
					nextNoodeRoleNames = roleNames.stream().collect(Collectors.joining(","));
					nextNoodeUserIds = userIds.stream().collect(Collectors.joining(","));
					nextNoodeUserNames = userNames.stream().collect(Collectors.joining(","));
				} else {
					nextNoodeUserIds = userIds.stream().collect(Collectors.joining(","));
					nextNoodeUserNames = userNames.stream().collect(Collectors.joining(","));
				}
			}
		}

		TmsApprovalNodeModel firstNode = tmsApprovalNodeModels.get(0);
		// 流程业务主表的作成
		TmsApprovalBusinessModel businessModel = new TmsApprovalBusinessModel();
		// 审批业务ID
		businessModel.setId(Long.valueOf(businessId));
		// 审批流程ID
		businessModel.setApprovalId(tmsApprovalHeaderModel.getApprovalId());
		// 审批流程类型 APPROVAL_FLOW_TYPE：1 货主审核 2 承运商审核
		businessModel.setApprovalFlowType(approvalOpenVO.getApprovalFlowType());
		// 审批对象
		businessModel.setApprovalObjectId(approvalOpenVO.getApprovalObjectId());
		businessModel.setApprovalObjectCode(approvalOpenVO.getApprovalObjectCode());
		businessModel.setApprovalObjectName(ToolKits.isEmpty(approvalOpenVO.getApprovalObjectName()) ? "" : approvalOpenVO.getApprovalObjectName());
		// 发起人
		businessModel.setInitiatedUserId(approvalOpenVO.getInitiatedUserId());
		businessModel.setInitiatedUserName(approvalOpenVO.getInitiatedUserName());
		businessModel.setInitiatedTime(date);
		// 状态 1发起申请
		businessModel.setStatus(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_APPLY);
		// 下一审批节点ID
		businessModel.setNextApproverNodeId(firstNode.getNodeId());
		// 下一审批角色或者用户
		businessModel.setNextApproverRoleId(nextNodeRoleIds);
		businessModel.setNextApproverRoleName(nextNoodeRoleNames);
		businessModel.setNextApproverUserId(nextNoodeUserIds);
		businessModel.setNextApproverUserName(nextNoodeUserNames);

		businessModel.setCreatetime(date);
		businessModel.setCreateperson(user.getNickname());
		businessModel.setUpdatetime(date);
		businessModel.setUpdateperson(user.getNickname());
		businessModel.setEnterpriseId(user.getEnterpriseId());
		businessModel.setEnterpriseName(user.getEnterpriseName());
		tmsApprovalBusinessMapper.save(businessModel);

		// 流程发起的日志作成
		ApprovalBusLogSaveVO logVO = new ApprovalBusLogSaveVO();
		logVO.setApprovalBusinessId(Long.valueOf(businessId));
		logVO.setApprovalId(tmsApprovalHeaderModel.getApprovalId());

		// 审批人ID
		logVO.setApproverPersonId(approvalOpenVO.getInitiatedUserId());
		logVO.setApproverPersonName(approvalOpenVO.getInitiatedUserName());
		logVO.setApprovalTime(date);
		logVO.setApprovalOpinion("发起申请");
		logVO.setResult(DataDictionaryConstant.NODE_APPROVAL_RESULT_APPLY);

		saveLogData(logVO);
		return true;
	}

	// 适配审批流程
	public TmsApprovalHeaderModel matchApproval(ApprovalOpenVO approvalOpenVO, UserEntity user) {
		// 添加查询条件
		Criteria criteria = Criteria.forClass(TmsApprovalHeaderModel.class);
		Restriction r1 = Restrictions.eq("approvalFlowType", approvalOpenVO.getApprovalFlowType());
		Restriction r2 = Restrictions.eq("status", DataDictionaryConstant.APPROVAL_STATUS_ENABLE);
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		List<TmsApprovalHeaderModel> tmsApprovalHeaderModels = tmsApprovalHeaderMapper.findByCriteria(criteria);

		if (ToolKits.isEmpty(tmsApprovalHeaderModels)) {
			return null;
		}

		if (approvalOpenVO.getApprovalFlowType().equals(DataDictionaryConstant.APPROVAL_FLOW_TYPE_CARRIER)) {
			// 匹配到承运商审批流
			return tmsApprovalHeaderModels.get(0);
		} else {
			// 其它四种审批流的匹配
			Map<Integer, String> conditionMap = Maps.newHashMap();
			// 配送方式
			if (ToolKits.isNotEmpty(approvalOpenVO.getDeliveryMethodType())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_DELIVERY, DataDictionaryConstant.APPROVAL_CONDITION_TYPE_DELIVERY + "_" +String.valueOf(approvalOpenVO.getDeliveryMethodType()));
			}
			// 订单类型
			if (ToolKits.isNotEmpty(approvalOpenVO.getOrderType())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_ORDER, DataDictionaryConstant.APPROVAL_CONDITION_TYPE_ORDER + "_" +String.valueOf(approvalOpenVO.getOrderType()));
			}
			// 订单业务类型
			if (ToolKits.isNotEmpty(approvalOpenVO.getOrderBusinessType())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_ORDER_BUSINESS, DataDictionaryConstant.APPROVAL_CONDITION_TYPE_ORDER_BUSINESS + "_" +String.valueOf(approvalOpenVO.getOrderBusinessType()));
			}
			// 运输模式
			if (ToolKits.isNotEmpty(approvalOpenVO.getTransportType())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_TRANSPORT, DataDictionaryConstant.APPROVAL_CONDITION_TYPE_TRANSPORT + "_" +String.valueOf(approvalOpenVO.getTransportType()));
			}
			// 温度要求
			if (ToolKits.isNotEmpty(approvalOpenVO.getTemperatureRequirement())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_TEMPERATURE, DataDictionaryConstant.APPROVAL_CONDITION_TYPE_TEMPERATURE + "_" +String.valueOf(approvalOpenVO.getTemperatureRequirement()));
			}
			// 货主ID
			if (ToolKits.isNotEmpty(approvalOpenVO.getCargoOwnerId())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_OWNER, String.valueOf(approvalOpenVO.getCargoOwnerId()));
			}

			// 部门ID
			if (ToolKits.isNotEmpty(approvalOpenVO.getDepartmentId())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_DEPARTMENT, String.valueOf(approvalOpenVO.getDepartmentId()));
			}

			// 发货方类型
			if (ToolKits.isNotEmpty(approvalOpenVO.getShipperType())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_SHIPPER, String.valueOf(approvalOpenVO.getShipperType()) + "," + String.valueOf(approvalOpenVO.getShipperUnitId()));
			}
			// 收货方类型
			if (ToolKits.isNotEmpty(approvalOpenVO.getConsigneeType())) {
				conditionMap.put(DataDictionaryConstant.APPROVAL_CONDITION_TYPE_CONSIGNEE, String.valueOf(approvalOpenVO.getConsigneeType()) + "," + String.valueOf(approvalOpenVO.getConsigneeUnitId()));
			}

			for (TmsApprovalHeaderModel approvalHeaderModel : tmsApprovalHeaderModels) {
				// 满足条件
				Criteria ctCriteria = Criteria.forClass(TmsApprovalCndModel.class);
				Restriction r4 = Restrictions.eq(TmsApprovalHeaderModel::getApprovalId, approvalHeaderModel.getApprovalId());
				Restriction r5 = Restrictions.eq(TmsApprovalHeaderModel::getEnterpriseId, user.getEnterpriseId());
				ctCriteria.setRestriction(Restrictions.and(r4, r5));
				List<TmsApprovalCndModel> approvalCndModels = tmsApprovalConditionMapper.findByCriteria(ctCriteria);

				if (ToolKits.isEmpty(approvalCndModels)) {
					continue;
				}

				// 判定满足条件
				int fitCnt = 0;
				for (TmsApprovalCndModel conditionModel : approvalCndModels) {
					switch (conditionModel.getApprovalConditionType().intValue()) {
					case 2:
					case 3:
						String[] cmpStr1 = conditionMap.get(conditionModel.getApprovalConditionType()).split(",");
						if (cmpStr1[0].equals(String.valueOf(conditionModel.getApprovalConditionValue())) && conditionModel.getUnitId().contains(cmpStr1[1])) {
							fitCnt++;
						}
						break;
					case 8:
					case 9:
						if (conditionModel.getUnitId().contains(conditionMap.get(conditionModel.getApprovalConditionType()))) {
							fitCnt++;
						}
						break;
					default:
						if (conditionMap.containsValue(conditionModel.getApprovalConditionType()+"_"+ String.valueOf(conditionModel.getApprovalConditionValue()))) {
							fitCnt++;
						}
						break;
					}
				}
				// 匹配到了审批流程
				if (fitCnt > 0 && fitCnt == approvalCndModels.size()) {
					return approvalHeaderModel;
				}
			}
		}
		return null;
	}

	/**
	 * 审批流程节点审核
	 *
	 * @param approvalBusinessNodeVO
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Boolean nodeApproval(ApprovalBusinessNodeVO approvalBusinessNodeVO) {
		ToolKits.isParamNull(approvalBusinessNodeVO, "审核请求参数不为空");
		ToolKits.isParamNull(approvalBusinessNodeVO.getApprovalBusinessId(), "审核请求业务流程ID不为空");
		ToolKits.isParamNull(approvalBusinessNodeVO.getNextApprovalNodeId(), "审核节点不为空");
		ToolKits.isParamNull(approvalBusinessNodeVO.getNextApprovalOrder(), "审核节点不为空");

		ToolKits.isParamNull(approvalBusinessNodeVO.getApproverPersonId(), "审核人不为空");
		ToolKits.isParamNull(approvalBusinessNodeVO.getApproverPersonName(), "审核人不为空");
		// 人员权限
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 验证审批人是否可以审批
		if (approvalBusinessNodeVO.getNodeApproverType().equals(DataDictionaryConstant.NODE_APPROVER_TYPE_ROLE)) {
			ToolKits.isParamNull(approvalBusinessNodeVO.getNextApproverRoleId(), "审核角色不为空");
			ToolKits.isParamNull(approvalBusinessNodeVO.getNextApproverRoleName(), "审核角色不为空");

			String[] tmpRoleIds = approvalBusinessNodeVO.getNextApproverRoleId().split(",");
			String[] tmpPersonRoleIds = approvalBusinessNodeVO.getApproverPersonRoleId().split(",");

			List<String> roleList = (List<String>) Arrays.stream(tmpRoleIds).filter(roleId -> Arrays.stream(tmpPersonRoleIds).collect(Collectors.toList()).contains(roleId)).collect(Collectors.toList());
			Assert.isTrue(roleList.size() > 0, "审核人【" + approvalBusinessNodeVO.getApproverPersonName() + "】不具备当前节点的审核角色");
			Assert.isTrue(approvalBusinessNodeVO.getNextApproverUserId().contains(String.valueOf(approvalBusinessNodeVO.getApproverPersonId())) && approvalBusinessNodeVO.getNextApproverUserName().contains(approvalBusinessNodeVO.getApproverPersonName()), "审核人【" + approvalBusinessNodeVO.getApproverPersonName() + "】不具备当前节点的审核角色");
		} else if (approvalBusinessNodeVO.getNodeApproverType().equals(DataDictionaryConstant.NODE_APPROVER_TYPE_USER)) {
			ToolKits.isParamNull(approvalBusinessNodeVO.getNextApproverUserId(), "审核用户不为空");
			ToolKits.isParamNull(approvalBusinessNodeVO.getNextApproverUserName(), "审核用户不为空");

			Assert.isTrue(approvalBusinessNodeVO.getNextApproverUserId().contains(String.valueOf(approvalBusinessNodeVO.getApproverPersonId())) && approvalBusinessNodeVO.getNextApproverUserName().contains(approvalBusinessNodeVO.getApproverPersonName()), "审核人【" + approvalBusinessNodeVO.getApproverPersonName() + "】不是当前节点的审核人");
		}

		// 判定当前节点是否最后一个节点
		boolean lastNode = false;
		boolean firstNode = false;
		// 流程是否结束
		boolean isFinish = false;

		Criteria criteriaApprovalBusDetail = Criteria.forClass(TmsApprovalBusDetailModel.class);
		Restriction r1 = Restrictions.eq("approvalBusinessId", approvalBusinessNodeVO.getApprovalBusinessId());
		Restriction r2 = Restrictions.eq("approvalId", approvalBusinessNodeVO.getApprovalId());
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteriaApprovalBusDetail.setRestriction(Restrictions.and(r1, r2, r3));
		criteriaApprovalBusDetail.setOrder(Order.newInstance().desc(new String[] { "approvalNodeOrder" }));
		List<TmsApprovalBusDetailModel> nodeApproverModels = tmsApprovalBusinessDetailMapper.findByCriteria(criteriaApprovalBusDetail);

		Assert.isTrue(!ToolKits.isEmpty(nodeApproverModels), "流程【" + approvalBusinessNodeVO.getApprovalObjectName() + "】审核失败");

		if (nodeApproverModels.get(0).getApprovalNodeId().longValue() == approvalBusinessNodeVO.getNextApprovalNodeId().longValue()) {
			lastNode = true;
		}
		if (nodeApproverModels.get(nodeApproverModels.size() - 1).getApprovalNodeId().longValue() == approvalBusinessNodeVO.getNextApprovalNodeId().longValue()) {
			firstNode = true;
		}

		// 会签 是否是最后一个审核者
		boolean lastApprover = false;
		if (approvalBusinessNodeVO.getNodeApprovalType().equals(DataDictionaryConstant.NODE_APPROVAL_TYPE_ALL)) {
			if (approvalBusinessNodeVO.getNextApproverUserId().split(",").length == 1) {
				lastApprover = true;
			}
		}
		// 更新审核业务主表
		Criteria criteriaBusinessModel = Criteria.forClass(TmsApprovalBusinessModel.class);
		Restriction r4 = Restrictions.eq("id", approvalBusinessNodeVO.getApprovalBusinessId());
		Restriction r5 = Restrictions.eq("approvalId", approvalBusinessNodeVO.getApprovalId());
		Restriction r6 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteriaBusinessModel.setRestriction(Restrictions.and(r4, r5, r6));

		// 更新审核明细表
		Criteria criteriaBusDetailModel = Criteria.forClass(TmsApprovalBusDetailModel.class);
		Restriction r7 = Restrictions.eq("approvalBusinessId", approvalBusinessNodeVO.getApprovalBusinessId());
		Restriction r8 = Restrictions.eq("approvalId", approvalBusinessNodeVO.getApprovalId());
		Restriction r9 = Restrictions.eq("approvalNodeId", approvalBusinessNodeVO.getNextApprovalNodeId());
		Restriction r10 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteriaBusDetailModel.setRestriction(Restrictions.and(r7, r8, r9, r10));

		// 当前日期
		Date date = DateUtil.date();

		Map<String, Object> mapBusiness = Maps.newHashMap();
		mapBusiness.put("updateperson", user.getNickname());
		mapBusiness.put("updatetime", date);

		Map<String, Object> mapBusinessDetail = Maps.newHashMap();
		mapBusinessDetail.put("updateperson", user.getNickname());
		mapBusinessDetail.put("updatetime", date);
		if (approvalBusinessNodeVO.getResult().equals(DataDictionaryConstant.NODE_APPROVAL_RESULT_REJECT_PREVIOUS)) {
			// 驳回上一级
			mapBusiness.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_REJECT);
			// 查询上一个节点审批人
			// 上一个节点是否是发起人
			if (firstNode) {
				// 发起人，下一节点信息为空,只有重新提交后，才能重新进入审批
				mapBusiness.put("nextApproverRoleId", "");
				mapBusiness.put("nextApproverRoleName", "");

				mapBusiness.put("nextApproverUserId", "");
				mapBusiness.put("nextApproverUserName", "");
				mapBusiness.put("nextApproverNodeId", null);
			} else {
				// 上一个节点不是发起人
				Criteria criteriaNodeApprover = Criteria.forClass(TmsApprovalNdApproverModel.class);
				Restriction r12 = Restrictions.eq("approvalId", approvalBusinessNodeVO.getApprovalId());
				Restriction r13 = Restrictions.eq("nodeOrder", approvalBusinessNodeVO.getNextApprovalOrder() - 1);
				Restriction r14 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
				criteriaNodeApprover.setRestriction(Restrictions.and(r12, r13, r14));
				List<TmsApprovalNdApproverModel> preNodeApprovers = tmsApprovalNdApproveMapper.findByCriteria(criteriaNodeApprover);
				Set<String> userIds = new HashSet<>();
				Set<String> userNames = new HashSet<>();
				Set<String> roleIds = new HashSet<>();
				Set<String> roleNames = new HashSet<>();
				Long preNodeId = null;
				for (TmsApprovalNdApproverModel approver : preNodeApprovers) {
					if (ToolKits.isNotEmpty(approver.getApproverRoleId())) {
						// role
						roleIds.add(String.valueOf(approver.getApproverRoleId()));
						roleNames.add(approver.getApproverRoleName());
						List<User> data1 = Lists.newArrayList();
						RestMessage<List<User>> Users = userTmsResource.usersByRoleId(null, null, String.valueOf(approver.getApproverRoleId()));
						if (!Users.isSuccess()) {
							throw new RuntimeException("审批角色【" + approver.getApproverRoleName() + "】下，没有用户!");
						} else {
							data1 = Users.getData();
						}
						for (User user1 : data1) {
							userIds.add(user1.getId());
							userNames.add(user1.getNickname());
						}
					} else {
						// user
						userIds.add(String.valueOf(approver.getApproverUserId()));
						userNames.add(approver.getApproverUserName());
					}
				}
				preNodeId = preNodeApprovers.get(0).getApprovalNodeId();

				String strRoleIds = roleIds.stream().collect(Collectors.joining(","));
				String strRoleNames = roleNames.stream().collect(Collectors.joining(","));
				String strUserIds = userIds.stream().collect(Collectors.joining(","));
				String strUserNames = userNames.stream().collect(Collectors.joining(","));
				// 驳回时，设置下一审批
				// 设置角色
				mapBusiness.put("nextApproverRoleId", strRoleIds);
				mapBusiness.put("nextApproverRoleName", strRoleNames);
				// 设置用户
				mapBusiness.put("nextApproverUserId", strUserIds);
				mapBusiness.put("nextApproverUserName", strUserNames);
				// 设置节点
				mapBusiness.put("nextApproverNodeId", preNodeId);
			}
			// 更新审批业务主表
			tmsApprovalBusinessMapper.updateMapByCriteria(mapBusiness, criteriaBusinessModel);

			// 更新审批明细表
			mapBusinessDetail.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_REJECT_PREVIOUS);
			mapBusinessDetail.put("approverPersonId", approvalBusinessNodeVO.getApproverPersonId());
			mapBusinessDetail.put("approverPersonName", approvalBusinessNodeVO.getApproverPersonName());
			mapBusinessDetail.put("approvalOpinion", approvalBusinessNodeVO.getApprovalOpinion());
			mapBusinessDetail.put("approvalTime", date);
			tmsApprovalBusinessDetailMapper.updateMapByCriteria(mapBusinessDetail, criteriaBusDetailModel);

			// 流程发起的日志作成
			ApprovalBusLogSaveVO logVO = new ApprovalBusLogSaveVO();
			logVO.setApprovalBusinessId(approvalBusinessNodeVO.getApprovalBusinessId());
			logVO.setApprovalId(approvalBusinessNodeVO.getApprovalId());
			// 审批人ID
			logVO.setApproverPersonId(approvalBusinessNodeVO.getApproverPersonId());
			logVO.setApproverPersonName(approvalBusinessNodeVO.getApproverPersonName());
//			logVO.setApproverRoleId();
			logVO.setApproverRoleName(approvalBusinessNodeVO.getNextApproverRoleName());
			logVO.setApproverUserId(approvalBusinessNodeVO.getApproverPersonId());
			logVO.setApproverUserName(approvalBusinessNodeVO.getApproverPersonName());
			logVO.setApprovalTime(date);
			logVO.setApprovalOpinion(approvalBusinessNodeVO.getApprovalOpinion());
			logVO.setResult(DataDictionaryConstant.NODE_APPROVAL_RESULT_REJECT_PREVIOUS);
			saveLogData(logVO);
		} else if (approvalBusinessNodeVO.getResult().equals(DataDictionaryConstant.NODE_APPROVAL_RESULT_REJECT_FIRST)) {
			// 查询第一个节点审批人
			// 发起人，下一节点信息为空,只有重新提交后，才能重新进入审批
			mapBusiness.put("nextApproverRoleId", "");
			mapBusiness.put("nextApproverRoleName", "");

			mapBusiness.put("nextApproverUserId", "");
			mapBusiness.put("nextApproverUserName", "");
			mapBusiness.put("nextApproverNodeId", null);
			// 驳回发起人
			mapBusiness.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_REJECT);
			// 更新审批业务主表
			tmsApprovalBusinessMapper.updateMapByCriteria(mapBusiness, criteriaBusinessModel);

			// 更新审批明细表
			mapBusinessDetail.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_REJECT_FIRST);
			mapBusinessDetail.put("approverPersonId", approvalBusinessNodeVO.getApproverPersonId());
			mapBusinessDetail.put("approverPersonName", approvalBusinessNodeVO.getApproverPersonName());
			mapBusinessDetail.put("approvalOpinion", approvalBusinessNodeVO.getApprovalOpinion());
			mapBusinessDetail.put("approvalTime", date);
			tmsApprovalBusinessDetailMapper.updateMapByCriteria(mapBusinessDetail, criteriaBusDetailModel);

			// 流程发起的日志作成
			ApprovalBusLogSaveVO logVO = new ApprovalBusLogSaveVO();
			logVO.setApprovalBusinessId(approvalBusinessNodeVO.getApprovalBusinessId());
			logVO.setApprovalId(approvalBusinessNodeVO.getApprovalId());
			// 审批人ID
			// logVO.setApproverRoleId();
			logVO.setApproverRoleName(approvalBusinessNodeVO.getNextApproverRoleName());
			logVO.setApproverUserId(approvalBusinessNodeVO.getApproverPersonId());
			logVO.setApproverUserName(approvalBusinessNodeVO.getApproverPersonName());
			logVO.setApproverPersonId(approvalBusinessNodeVO.getApproverPersonId());
			logVO.setApproverPersonName(approvalBusinessNodeVO.getApproverPersonName());
			logVO.setApprovalTime(date);
			logVO.setApprovalOpinion(approvalBusinessNodeVO.getApprovalOpinion());
			logVO.setResult(DataDictionaryConstant.NODE_APPROVAL_RESULT_REJECT_FIRST);
			saveLogData(logVO);
		} else if (approvalBusinessNodeVO.getResult().equals(DataDictionaryConstant.NODE_APPROVAL_RESULT_PASS)) {
			// 审批通过
			if (lastNode) {
				// 最后一个节点审批通过
				if (approvalBusinessNodeVO.getNodeApprovalType().equals(DataDictionaryConstant.NODE_APPROVAL_TYPE_ALL)) {
					// 会签
					if (!lastApprover) {
						// 不是最后一个审批者
						mapBusiness.put("nextApproverUserId", subStr(approvalBusinessNodeVO.getNextApproverUserId(), String.valueOf(approvalBusinessNodeVO.getApproverPersonId())));
						mapBusiness.put("nextApproverUserName", subStr(approvalBusinessNodeVO.getNextApproverUserName(), approvalBusinessNodeVO.getApproverPersonName()));
					} else {
						mapBusiness.put("nextApproverUserId", "");
						mapBusiness.put("nextApproverUserName", "");
						mapBusiness.put("nextApproverRoleId", "");
						mapBusiness.put("nextApproverRoleName", "");
						mapBusiness.put("nextApproverNodeId", null);

						mapBusinessDetail.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_PASS);
						mapBusiness.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_FINISHED);
						isFinish = true;
					}
					// 更新审批业务主表
					tmsApprovalBusinessMapper.updateMapByCriteria(mapBusiness, criteriaBusinessModel);
					// 更新审批明细表
					mapBusinessDetail.put("approverPersonId", approvalBusinessNodeVO.getApproverPersonId());
					mapBusinessDetail.put("approverPersonName", approvalBusinessNodeVO.getApproverPersonName());
					mapBusinessDetail.put("approvalOpinion", approvalBusinessNodeVO.getApprovalOpinion());
					mapBusinessDetail.put("approvalTime", date);
					tmsApprovalBusinessDetailMapper.updateMapByCriteria(mapBusinessDetail, criteriaBusDetailModel);
				} else {
					mapBusiness.put("nextApproverUserId", "");
					mapBusiness.put("nextApproverUserName", "");
					mapBusiness.put("nextApproverRoleId", "");
					mapBusiness.put("nextApproverRoleName", "");
					mapBusiness.put("nextApproverNodeId", null);
					mapBusiness.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_FINISHED);
					// 更新审批业务主表
					tmsApprovalBusinessMapper.updateMapByCriteria(mapBusiness, criteriaBusinessModel);
					// 更新审批明细表
					mapBusinessDetail.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_PASS);
					mapBusinessDetail.put("approverPersonId", approvalBusinessNodeVO.getApproverPersonId());
					mapBusinessDetail.put("approverPersonName", approvalBusinessNodeVO.getApproverPersonName());
					mapBusinessDetail.put("approvalOpinion", approvalBusinessNodeVO.getApprovalOpinion());
					mapBusinessDetail.put("approvalTime", date);
					tmsApprovalBusinessDetailMapper.updateMapByCriteria(mapBusinessDetail, criteriaBusDetailModel);

					isFinish = true;
				}
			} else {
				// 中间节点审批通过
				if (approvalBusinessNodeVO.getNodeApprovalType().equals(DataDictionaryConstant.NODE_APPROVAL_TYPE_ALL)) {
					// 会签
					if (!lastApprover) {
						// 不是最后一个审批者
						mapBusiness.put("nextApproverUserId", subStr(approvalBusinessNodeVO.getNextApproverUserId(), String.valueOf(approvalBusinessNodeVO.getApproverPersonId())));
						mapBusiness.put("nextApproverUserName", subStr(approvalBusinessNodeVO.getNextApproverUserName(), approvalBusinessNodeVO.getApproverPersonName()));
					} else {
						// 查询下一个节点审批人
						Criteria criteriaNodeApprover = Criteria.forClass(TmsApprovalNdApproverModel.class);
						Restriction r12 = Restrictions.eq("approvalId", approvalBusinessNodeVO.getApprovalId());
						Restriction r13 = Restrictions.eq("nodeOrder", approvalBusinessNodeVO.getNextApprovalOrder() + 1);
						Restriction r14 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
						criteriaNodeApprover.setRestriction(Restrictions.and(r12, r13, r14));
						List<TmsApprovalNdApproverModel> nextNodeApprovers = tmsApprovalNdApproveMapper.findByCriteria(criteriaNodeApprover);
						Set<String> userIds = new HashSet<>();
						Set<String> userNames = new HashSet<>();
						Set<String> roleIds = new HashSet<>();
						Set<String> roleNames = new HashSet<>();
						Long nextNodeId = null;
						for (TmsApprovalNdApproverModel approver : nextNodeApprovers) {
							if (ToolKits.isNotEmpty(approver.getApproverRoleId())) {
								// role
								roleIds.add(String.valueOf(approver.getApproverRoleId()));
								roleNames.add(approver.getApproverRoleName());
								List<User> data1 = Lists.newArrayList();
								RestMessage<List<User>> Users = userTmsResource.usersByRoleId(null, null, String.valueOf(approver.getApproverRoleId()));
								if (!Users.isSuccess()) {
									throw new RuntimeException("审批角色【" + approver.getApproverRoleName() + "】下，没有用户!");
								} else {
									data1 = Users.getData();
								}
								for (User user1 : data1) {
									userIds.add(user1.getId());
									userNames.add(user1.getNickname());
								}
							} else {
								// user
								userIds.add(String.valueOf(approver.getApproverUserId()));
								userNames.add(approver.getApproverUserName());
							}
						}
						nextNodeId = nextNodeApprovers.get(0).getApprovalNodeId();

						String strRoleIds = roleIds.stream().collect(Collectors.joining(","));
						String strRoleNames = roleNames.stream().collect(Collectors.joining(","));
						String strUserIds = userIds.stream().collect(Collectors.joining(","));
						String strUserNames = userNames.stream().collect(Collectors.joining(","));

						mapBusiness.put("nextApproverRoleId", strRoleIds);
						mapBusiness.put("nextApproverRoleName", strRoleNames);

						mapBusiness.put("nextApproverUserId", strUserIds);
						mapBusiness.put("nextApproverUserName", strUserNames);

						mapBusiness.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_VERIFY);
						mapBusinessDetail.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_PASS);
						mapBusiness.put("nextApproverNodeId", nextNodeId);
					}
					// 更新审批业务主表
					tmsApprovalBusinessMapper.updateMapByCriteria(mapBusiness, criteriaBusinessModel);
					// 更新审批明细表
					mapBusinessDetail.put("approverPersonId", approvalBusinessNodeVO.getApproverPersonId());
					mapBusinessDetail.put("approverPersonName", approvalBusinessNodeVO.getApproverPersonName());
					mapBusinessDetail.put("approvalOpinion", approvalBusinessNodeVO.getApprovalOpinion());
					mapBusinessDetail.put("approvalTime", date);
					tmsApprovalBusinessDetailMapper.updateMapByCriteria(mapBusinessDetail, criteriaBusDetailModel);
				} else {
					// 或签
					// 查询下一个节点审批人
					Criteria criteriaNodeApprover = Criteria.forClass(TmsApprovalNdApproverModel.class);
					Restriction r12 = Restrictions.eq("approvalId", approvalBusinessNodeVO.getApprovalId());
					Restriction r13 = Restrictions.eq("nodeOrder", approvalBusinessNodeVO.getNextApprovalOrder() + 1);
					Restriction r14 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
					criteriaNodeApprover.setRestriction(Restrictions.and(r12, r13, r14));
					List<TmsApprovalNdApproverModel> nextNodeApprovers = tmsApprovalNdApproveMapper.findByCriteria(criteriaNodeApprover);
					Assert.isTrue(!ToolKits.isEmpty(nextNodeApprovers), "审批流程【" + approvalBusinessNodeVO.getApprovalId() + "】的下一个审批节点不存在");

					Set<String> userIds = new HashSet<>();
					Set<String> userNames = new HashSet<>();
					Set<String> roleIds = new HashSet<>();
					Set<String> roleNames = new HashSet<>();
					Long nextNodeId = null;
					for (TmsApprovalNdApproverModel approver : nextNodeApprovers) {
						if (ToolKits.isNotEmpty(approver.getApproverRoleId())) {
							// role
							roleIds.add(String.valueOf(approver.getApproverRoleId()));
							roleNames.add(approver.getApproverRoleName());
							List<User> data1 = Lists.newArrayList();
							RestMessage<List<User>> Users = userTmsResource.usersByRoleId(null, null, String.valueOf(approver.getApproverRoleId()));
							if (!Users.isSuccess()) {
								throw new RuntimeException("审批角色【" + approver.getApproverRoleName() + "】下，没有用户!");
							} else {
								data1 = Users.getData();
							}
							for (User user1 : data1) {
								userIds.add(user1.getId());
								userNames.add(user1.getNickname());
							}
						} else {
							// user
							userIds.add(String.valueOf(approver.getApproverUserId()));
							userNames.add(approver.getApproverUserName());
						}
					}
					nextNodeId = nextNodeApprovers.get(0).getApprovalNodeId();

					String strRoleIds = roleIds.stream().collect(Collectors.joining(","));
					String strRoleNames = roleNames.stream().collect(Collectors.joining(","));
					String strUserIds = userIds.stream().collect(Collectors.joining(","));
					String strUserNames = userNames.stream().collect(Collectors.joining(","));

					mapBusiness.put("nextApproverRoleId", strRoleIds);
					mapBusiness.put("nextApproverRoleName", strRoleNames);
					mapBusiness.put("nextApproverUserId", strUserIds);
					mapBusiness.put("nextApproverUserName", strUserNames);
					mapBusiness.put("nextApproverNodeId", nextNodeId);
				}
				// 更新审批业务主表
				mapBusiness.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_VERIFY);
				tmsApprovalBusinessMapper.updateMapByCriteria(mapBusiness, criteriaBusinessModel);

				// 更新审批明细表
				mapBusinessDetail.put("status", DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_PASS);
				mapBusinessDetail.put("approverPersonId", approvalBusinessNodeVO.getApproverPersonId());
				mapBusinessDetail.put("approverPersonName", approvalBusinessNodeVO.getApproverPersonName());
				mapBusinessDetail.put("approvalOpinion", approvalBusinessNodeVO.getApprovalOpinion());
				mapBusinessDetail.put("approvalTime", date);
				tmsApprovalBusinessDetailMapper.updateMapByCriteria(mapBusinessDetail, criteriaBusDetailModel);
			}

			// 流程发起的日志作成
			ApprovalBusLogSaveVO logVO = new ApprovalBusLogSaveVO();
			logVO.setApprovalBusinessId(approvalBusinessNodeVO.getApprovalBusinessId());
			logVO.setApprovalId(approvalBusinessNodeVO.getApprovalId());
			// 审批人ID
			// logVO.setApproverRoleId();
			logVO.setApproverRoleName(approvalBusinessNodeVO.getNextApproverRoleName());
			logVO.setApproverUserId(approvalBusinessNodeVO.getApproverPersonId());
			logVO.setApproverUserName(approvalBusinessNodeVO.getApproverPersonName());
			logVO.setApproverPersonId(approvalBusinessNodeVO.getApproverPersonId());
			logVO.setApproverPersonName(approvalBusinessNodeVO.getApproverPersonName());
			logVO.setApprovalTime(date);
			logVO.setApprovalOpinion(approvalBusinessNodeVO.getApprovalOpinion());
			logVO.setResult(DataDictionaryConstant.NODE_APPROVAL_RESULT_PASS);
			saveLogData(logVO);
		}
		return isFinish;
	}

	/**
	 * 首页 我发起的审批流程查询
	 *
	 * @param vo
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<ApplyApprovalQueryDTO> applyApproval(ApplyApprovalVO vo) {

		ToolKits.isParamNull(vo, "我发起的审批流程查询请求参数不为空");
		ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");

		// 人员权限
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 审批流程状态名称
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS, null, null, null);

		// 审批流程类型名称
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.APPROVAL_FLOW_TYPE, null, null, null);

		Criteria criteriaApprovalBusiness = Criteria.forClass(TmsApprovalBusinessModel.class);
		Restriction r1 = Restrictions.eq("initiatedUserId", vo.getUserId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteriaApprovalBusiness.setRestriction(Restrictions.and(r1, r2));
		criteriaApprovalBusiness.setOrder(Order.newInstance().desc(new String[] { "initiatedTime" }));
		PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
		List<TmsApprovalBusinessModel> approvalBusinessModels = tmsApprovalBusinessMapper.findByCriteria(criteriaApprovalBusiness);

		List<ApplyApprovalQueryDTO> dtos = new ArrayList<>();
		for (TmsApprovalBusinessModel businessModel : approvalBusinessModels) {
			ApplyApprovalQueryDTO applyApprovalQueryDTO = new ApplyApprovalQueryDTO();
			BeanUtils.copyProperties(businessModel, applyApprovalQueryDTO);

			applyApprovalQueryDTO.setStatusName(PublicMethods.change(restMessage1, String.valueOf(businessModel.getStatus())));

			applyApprovalQueryDTO.setApprovalFlowTypeName(PublicMethods.change(restMessage2, String.valueOf(businessModel.getApprovalFlowType())));

			dtos.add(applyApprovalQueryDTO);
		}

		// 分页重组
		Page<ApplyApprovalQueryDTO> page = PageUtils.getPage(dtos);
		if (approvalBusinessModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsApprovalBusinessModel> p0 = (com.github.pagehelper.Page<TmsApprovalBusinessModel>) approvalBusinessModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 首页 待我审批的审批流程查询
	 *
	 * @param vo
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<PendingApprovalQueryDTO> pendingApproval(ApplyApprovalVO vo) {
		ToolKits.isParamNull(vo, "我发起的审批流程查询请求参数不为空");
		ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");
		// 人员权限
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 审批流程状态名称
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS, null, null, null);
		// 审批流程类型名称
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.APPROVAL_FLOW_TYPE, null, null, null);

		Criteria criteriaApprovalBusiness = Criteria.forClass(TmsApprovalBusinessModel.class);
		Restriction r1 = ToolKits.isEmpty(vo.getUserId()) ? null : Restrictions.like("nextApproverUserId", "%" + vo.getUserId() + "%");
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		Restriction r3 = Restrictions.lt(TmsApprovalBusinessModel::getStatus, DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_INVALID);
		criteriaApprovalBusiness.setRestriction(Restrictions.and(r1, r2, r3));
		criteriaApprovalBusiness.setOrder(Order.newInstance().desc(new String[] { "initiatedTime" }));

		PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
		List<TmsApprovalBusinessModel> approvalBusinessModels = tmsApprovalBusinessMapper.findByCriteria(criteriaApprovalBusiness);

		List<PendingApprovalQueryDTO> dtos = new ArrayList<>();
		for (TmsApprovalBusinessModel businessModel : approvalBusinessModels) {
			PendingApprovalQueryDTO dto = new PendingApprovalQueryDTO();
			BeanUtils.copyProperties(businessModel, dto);
			// 下一个节点查询
			Criteria criteriaNode = Criteria.forClass(TmsApprovalNodeModel.class);
			Restriction r4 = Restrictions.eq("approvalId", businessModel.getApprovalId());
			Restriction r5 = Restrictions.eq("nodeId", businessModel.getNextApproverNodeId());
			Restriction r6 = Restrictions.eq("status", DataDictionaryConstant.NODE_STATUS_ENABLE);
			Restriction r7 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaNode.setRestriction(Restrictions.and(r4, r5, r6, r7));
			List<TmsApprovalNodeModel> tmsApprovalNodeModels = tmsApprovalNodeMapper.findByCriteria(criteriaNode);
			Assert.isTrue(ToolKits.isNotEmpty(tmsApprovalNodeModels) && tmsApprovalNodeModels.size() > 0, "待我审批查询失败");

			TmsApprovalNodeModel nodeModel = tmsApprovalNodeModels.get(0);
			dto.setNextApprovalOrder(nodeModel.getNodeOrder());
			dto.setStatusName(PublicMethods.change(restMessage1, String.valueOf(businessModel.getStatus())));
			dto.setApprovalFlowTypeName(PublicMethods.change(restMessage2, String.valueOf(businessModel.getApprovalFlowType())));
			dto.setNodeApprovalType(nodeModel.getNodeApprovalType());
			dto.setNodeApproverType(nodeModel.getNodeApproverType());
			dtos.add(dto);
		}
		// 分页重组
		Page<PendingApprovalQueryDTO> page = PageUtils.getPage(dtos);
		if (approvalBusinessModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsApprovalBusinessModel> p0 = (com.github.pagehelper.Page<TmsApprovalBusinessModel>) approvalBusinessModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 首页 我已处理的审批流程查询
	 *
	 * @param vo
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<ApplyApprovalQueryDTO> processedApproval(ApplyApprovalVO vo) {
		ToolKits.isParamNull(vo, "我发起的审批流程查询请求参数不为空");
		ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");
		// 人员权限
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		List<ApplyApprovalQueryDTO> rs = new ArrayList<>();

		// 审批流程状态名称
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS, null, null, null);
		// 审批流程类型名称
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.APPROVAL_FLOW_TYPE, null, null, null);

		// 查询已审批的流程ID
		// List<Long> businessIds =
		// tmsApprovalBusinessDetailMapper.queryApprovalBusinessIds(approvalUserId,
		// DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_PENDING,
		// user.getEnterpriseId());
		Criteria criteria = Criteria.forClass(TmsApprovalBusLogModel.class);
		Restriction r1 = Restrictions.eq("approverPersonId", vo.getUserId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));

		List<TmsApprovalBusLogModel> tmsApprovalBusLogModels = tmsApprovalBusinessLogMapper.findByCriteria(criteria);
		Set<Long> ids = Sets.newHashSet();
		for (TmsApprovalBusLogModel log : tmsApprovalBusLogModels) {
			ids.add(log.getApprovalBusinessId());
		}
		List<Long> businessIds = ids.stream().collect(Collectors.toList());
		if (ToolKits.isNotEmpty(businessIds)) {
			Criteria criteriaApprovalBusiness = Criteria.forClass(TmsApprovalBusinessModel.class);
			Restriction r3 = Restrictions.in("id", businessIds.stream().toArray());
			Restriction r4 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaApprovalBusiness.setRestriction(Restrictions.and(r3, r4));
			criteriaApprovalBusiness.setOrder(Order.newInstance().desc(new String[] { "initiatedTime" }));

			PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
			List<TmsApprovalBusinessModel> approvalBusinessModels = tmsApprovalBusinessMapper.findByCriteria(criteriaApprovalBusiness);
			for (TmsApprovalBusinessModel businessModel : approvalBusinessModels) {
				ApplyApprovalQueryDTO dto = new ApplyApprovalQueryDTO();
				BeanUtils.copyProperties(businessModel, dto);
				dto.setStatusName(PublicMethods.change(restMessage1, String.valueOf(businessModel.getStatus())));
				dto.setApprovalFlowTypeName(PublicMethods.change(restMessage2, String.valueOf(businessModel.getApprovalFlowType())));
				rs.add(dto);
			}
			// 分页重组
			Page<ApplyApprovalQueryDTO> page = PageUtils.getPage(rs);
			if (approvalBusinessModels instanceof com.github.pagehelper.Page) {
				com.github.pagehelper.Page<TmsApprovalBusinessModel> p0 = (com.github.pagehelper.Page<TmsApprovalBusinessModel>) approvalBusinessModels;
				page.setPageCount(p0.getPages());
				page.setPageNum(p0.getPageNum());
				page.setPageSize(p0.getPageSize());
				page.setTotalCount(p0.getTotal());
				page.setStartRow(p0.getStartRow());
				page.setEndRow(p0.getEndRow());
			}
			return page;
		}
		return null;
	}

	/**
	 * 审核业务日志新增
	 *
	 * @param approvalBusLogSaveVO
	 */
	@Override
	public void saveLogData(ApprovalBusLogSaveVO approvalBusLogSaveVO) {
		ToolKits.isParamNull(approvalBusLogSaveVO.getApprovalBusinessId(), "审批业务ID不为空");
		ToolKits.isParamNull(approvalBusLogSaveVO.getApprovalId(), "审批流程ID不为空");
		ToolKits.isParamNull(approvalBusLogSaveVO.getApproverPersonId(), "审批人ID不为空");
		ToolKits.isParamNull(approvalBusLogSaveVO.getApproverPersonName(), "审批人名称不为空");
		ToolKits.isParamNull(approvalBusLogSaveVO.getApprovalTime(), "审批时间不为空");
		ToolKits.isParamNull(approvalBusLogSaveVO.getResult(), "审批日志结果不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 当前时间
		Date date = DateUtil.date();

		String id = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_APPROVAL_BUSINESS_LOG_ID, "L");
		ToolKits.isParamNull(id, "审核业务日志ID生成失败");

		TmsApprovalBusLogModel tmsApprovalBusLogModel = new TmsApprovalBusLogModel();
		BeanUtils.copyProperties(approvalBusLogSaveVO, tmsApprovalBusLogModel);

		// 日志ID赋值
		tmsApprovalBusLogModel.setId(Long.valueOf(id));

		// 基础赋值
		tmsApprovalBusLogModel.setEnterpriseId(user.getEnterpriseId());
		tmsApprovalBusLogModel.setEnterpriseName(user.getEnterpriseName());
		tmsApprovalBusLogModel.setCreateperson(user.getNickname());
		tmsApprovalBusLogModel.setCreatetime(date);
		tmsApprovalBusLogModel.setUpdateperson(user.getNickname());
		tmsApprovalBusLogModel.setUpdatetime(date);
		tmsApprovalBusLogModel.setEnterpriseId(user.getEnterpriseId());
		tmsApprovalBusLogModel.setEnterpriseName(user.getEnterpriseName());

		// 保存
		tmsApprovalBusinessLogMapper.save(tmsApprovalBusLogModel);
	}

	/**
	 * 审核作废
	 *
	 * @param approvalBusinessId
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void approvalInvalidData(Long approvalBusinessId) {
		ToolKits.isParamNull(approvalBusinessId, "审批业务ID不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 查询审批业务
		TmsApprovalBusinessModel tmsApprovalBusinessModel = tmsApprovalBusinessMapper.findById(approvalBusinessId, TmsApprovalBusinessModel.class);
		ToolKits.isParamNull(tmsApprovalBusinessModel, "审批业务ID[" + approvalBusinessId + "]有误,查询为空!");

		// 判断是否为发起人操作
		Assert.isTrue(tmsApprovalBusinessModel.getInitiatedUserId().equals(user.getUserid()), "作废操作只能由发起人操作!");

		// 判断是否审批流已结束
		Assert.isTrue(!(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_FINISHED.equals(tmsApprovalBusinessModel.getStatus())), "该审批已结束不可作废!");

		// 当前时间
		Date date = DateUtil.date();

		// 修改业务表信息
		tmsApprovalBusinessModel.setStatus(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_INVALID);
		tmsApprovalBusinessModel.setUpdateperson(user.getNickname());
		tmsApprovalBusinessModel.setUpdatetime(date);
		tmsApprovalBusinessMapper.update(tmsApprovalBusinessModel);

		// 流程作废的日志生成
		ApprovalBusLogSaveVO logVO = new ApprovalBusLogSaveVO();
		logVO.setApprovalBusinessId(approvalBusinessId);
		logVO.setApprovalId(tmsApprovalBusinessModel.getApprovalId());

		// 审批人ID
		logVO.setApproverPersonId(user.getUserid());
		logVO.setApproverPersonName(user.getNickname());
//		logVO.setApproverRoleId();
//		logVO.setApproverRoleName();
		logVO.setApproverUserId(user.getUserid());
		logVO.setApproverUserName(user.getNickname());
		logVO.setApprovalTime(date);
		logVO.setResult(DataDictionaryConstant.NODE_APPROVAL_RESULT_INVALID);

		saveLogData(logVO);
	}

	/**
	 * 审核撤回
	 *
	 * @param approvalBusinessId
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void approvalRetractData(Long approvalBusinessId) {
		ToolKits.isParamNull(approvalBusinessId, "审批业务ID不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 查询审批业务
		TmsApprovalBusinessModel tmsApprovalBusinessModel = tmsApprovalBusinessMapper.findById(approvalBusinessId, TmsApprovalBusinessModel.class);
		ToolKits.isParamNull(tmsApprovalBusinessModel, "审批业务ID[" + approvalBusinessId + "]有误,查询为空!");

		// 判断是否为发起人操作
		Assert.isTrue(tmsApprovalBusinessModel.getInitiatedUserId().equals(user.getUserid()), "撤回操作只能由发起人操作!");

		// 判断是否审批流已结束
		Assert.isTrue(!(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_FINISHED.equals(tmsApprovalBusinessModel.getStatus())), "该审批已结束不可作废!");

		// 当前时间
		Date date = DateUtil.date();

		// 修改业务表信息
		tmsApprovalBusinessModel.setStatus(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_RETRACT);
		tmsApprovalBusinessModel.setUpdateperson(user.getNickname());
		tmsApprovalBusinessModel.setUpdatetime(date);
		tmsApprovalBusinessMapper.update(tmsApprovalBusinessModel);

		// 修改所以审批业务节点信息
		Criteria criteria = Criteria.forClass(TmsApprovalBusLogModel.class);
		Restriction r1 = Restrictions.eq("approvalBusinessId", approvalBusinessId);
		criteria.setRestriction(r1);

		Map<String, Object> map = Maps.newHashMap();
		map.put("result", DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS_PENDING);
		map.put("updateperson", user.getNickname());
		map.put("updatetime", date);

		tmsApprovalBusinessDetailMapper.updateMapByCriteria(map, criteria);

		// 流程作废的日志生成
		ApprovalBusLogSaveVO logVO = new ApprovalBusLogSaveVO();
		logVO.setApprovalBusinessId(approvalBusinessId);
		logVO.setApprovalId(tmsApprovalBusinessModel.getApprovalId());

		// 审批人ID
		logVO.setApproverPersonId(user.getUserid());
		logVO.setApproverPersonName(user.getNickname());

		logVO.setApproverUserId(user.getUserid());
		logVO.setApproverUserName(user.getNickname());
		logVO.setApprovalTime(date);
		logVO.setResult(DataDictionaryConstant.NODE_APPROVAL_RESULT_RETRACT);

		saveLogData(logVO);
	}

	/**
	 * 审核提交
	 *
	 * @param approvalBusinessId
	 */
	@Override
	public void approvalSubmitData(Long approvalBusinessId) {
		ToolKits.isParamNull(approvalBusinessId, "审批业务ID不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 查询审批业务
		TmsApprovalBusinessModel tmsApprovalBusinessModel = tmsApprovalBusinessMapper.findById(approvalBusinessId, TmsApprovalBusinessModel.class);
		ToolKits.isParamNull(tmsApprovalBusinessModel, "审批业务ID[" + approvalBusinessId + "]有误,查询为空!");

		// 判断是否为发起人操作
		Assert.isTrue(tmsApprovalBusinessModel.getInitiatedUserId().equals(user.getUserid()), "提交操作只能由发起人操作!");

		// 判断提交按钮是否可用
		if ((DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_REJECT.equals(tmsApprovalBusinessModel.getStatus()) && ToolKits.isEmpty(tmsApprovalBusinessModel.getNextApproverUserName())) || DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_RETRACT.equals(tmsApprovalBusinessModel.getStatus())) {

			// 当前时间
			Date date = DateUtil.date();

			// 修改业务表信息
			tmsApprovalBusinessModel.setStatus(DataDictionaryConstant.APPROVAL_BUSINESS_STATUS_SUBMIT);
			tmsApprovalBusinessModel.setUpdateperson(user.getNickname());
			tmsApprovalBusinessModel.setUpdatetime(date);

			// 获取第一个节点信息
			Criteria criteria = Criteria.forClass(TmsApprovalBusDetailModel.class);
			Restriction r1 = Restrictions.eq("approvalBusinessId", approvalBusinessId);
			criteria.setRestriction(r1);
			criteria.setOrder(Order.newInstance().asc(new String[] { "approvalNodeId" }));

			List<TmsApprovalBusDetailModel> tmsApprovalBusDetailModels = tmsApprovalBusinessDetailMapper.findByCriteria(criteria);
			ToolKits.isParamNull(tmsApprovalBusDetailModels, "对应的审批节点为空");
			TmsApprovalBusDetailModel tmsApprovalBusDetailModel = tmsApprovalBusDetailModels.get(0);

			// 修改下一个节点
			tmsApprovalBusinessModel.setNextApproverNodeId(tmsApprovalBusDetailModel.getApprovalNodeId());

			// 修改下一个角色和下一个用户
			tmsApprovalBusinessModel.setNextApproverRoleId(tmsApprovalBusDetailModel.getApproverRoleId());
			tmsApprovalBusinessModel.setNextApproverRoleName(tmsApprovalBusDetailModel.getApproverRoleName());
			tmsApprovalBusinessModel.setNextApproverUserId(tmsApprovalBusDetailModel.getApproverUserId());
			tmsApprovalBusinessModel.setNextApproverUserName(tmsApprovalBusDetailModel.getApproverUserName());

			// 执行修改
			tmsApprovalBusinessMapper.update(tmsApprovalBusinessModel);

			// 流程作废的日志生成
			ApprovalBusLogSaveVO logVO = new ApprovalBusLogSaveVO();
			logVO.setApprovalBusinessId(approvalBusinessId);
			logVO.setApprovalId(tmsApprovalBusinessModel.getApprovalId());

			// 审批人ID
			logVO.setApproverPersonId(user.getUserid());
			logVO.setApproverPersonName(user.getNickname());

			logVO.setApproverUserId(user.getUserid());
			logVO.setApproverUserName(user.getNickname());
			logVO.setApprovalTime(date);
			logVO.setResult(DataDictionaryConstant.NODE_APPROVAL_RESULT_APPLY);
			saveLogData(logVO);

		} else {
			throw new RuntimeException("当前状态提交按钮不可使用!");
		}
	}

	/**
	 * 查询审核历史
	 *
	 * @param approvalBusinessId
	 * @return
	 */
	@Override
	public List<ApprovalLogDTO> getBusLogData(String approvalBusinessId) {
		ToolKits.isParamNull(approvalBusinessId, "审批业务ID不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 查询审核历史
		Criteria criteria = Criteria.forClass(TmsApprovalBusLogModel.class);
		Restriction r1 = Restrictions.eq("approvalBusinessId", approvalBusinessId);
		criteria.setRestriction(r1);
		criteria.setOrder(Order.newInstance().asc("createtime"));

		List<TmsApprovalBusLogModel> tmsApprovalBusLogModels = tmsApprovalBusinessLogMapper.findByCriteria(criteria);

		List<ApprovalLogDTO> dtoList = Lists.newArrayList();
		// 审批日志 结果
		List<Map<String, Object>> restMessageLogRs = sysRefdatadService.getDropDownById(DataDictionaryConstant.NODE_APPROVAL_RESULT, null, null, null);

		tmsApprovalBusLogModels.forEach(logDto -> {
			ApprovalLogDTO dto = new ApprovalLogDTO();
			BeanUtils.copyProperties(logDto, dto);
			dto.setResultName(PublicMethods.change(restMessageLogRs, String.valueOf(logDto.getResult())));
			dtoList.add(dto);
		});
		return dtoList;
	}

	/**
	 * 查询审核节点
	 *
	 * @param approvalBusinessId
	 * @return
	 */
	@Override
	public List<ApprovalNodeSelDTO> getBusDetailData(String approvalBusinessId) {
		ToolKits.isParamNull(approvalBusinessId, "审批业务ID不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		// 查询审核历史
		Criteria criteria = Criteria.forClass(TmsApprovalBusDetailModel.class);
		Restriction r1 = Restrictions.eq("approvalBusinessId", approvalBusinessId);
		criteria.setRestriction(r1);
		criteria.setOrder(Order.newInstance().asc("createtime"));

		List<TmsApprovalBusDetailModel> tmsApprovalBusDetailModels = tmsApprovalBusinessDetailMapper.findByCriteria(criteria);

		List<ApprovalNodeSelDTO> dtoList = Lists.newArrayList();

		// 审批节点 状态
		List<Map<String, Object>> restMessageLogRs = sysRefdatadService.getDropDownById(DataDictionaryConstant.APPROVAL_BUSINESS_NODE_STATUS, null, null, null);

		tmsApprovalBusDetailModels.forEach(logDto -> {
			ApprovalNodeSelDTO dto = new ApprovalNodeSelDTO();
			BeanUtils.copyProperties(logDto, dto);
			dto.setStatusName(PublicMethods.change(restMessageLogRs, String.valueOf(logDto.getStatus())));
			dtoList.add(dto);
		});
		return dtoList;
	}

	// 去掉当前审批者
	public String subStr(String str, String removeStr) {
		String[] arr = str.split(",");
		return Arrays.stream(arr).filter(s -> !s.equals(removeStr)).collect(Collectors.joining(","));
	}
}
