package com.zd.laboratory.onemachine.service;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.zd.common.core.constant.Constants;
import com.zd.common.core.constant.UserConstants;
import com.zd.common.core.domain.R;
import com.zd.common.core.enums.SignEnum;
import com.zd.common.core.exception.ServiceException;
import com.zd.common.core.utils.Assert;
import com.zd.common.core.utils.DateUtils;
import com.zd.common.core.utils.IdUtils;
import com.zd.common.core.utils.StringUtils;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.redis.service.RedisService;
import com.zd.common.security.service.TokenService;
import com.zd.laboratory.domain.*;
import com.zd.laboratory.domain.dto.LabViolationDTO;
import com.zd.laboratory.domain.vo.*;
import com.zd.laboratory.mapper.LabHardwareStateMapper;
import com.zd.laboratory.mapper.LabSubjectAccessRecordMapper;
import com.zd.laboratory.mapper.LabSubjectSecurityconfigureMapper;
import com.zd.laboratory.onemachine.domain.SignInPerInfoVO;
import com.zd.laboratory.onemachine.domain.SignInfoVO;
import com.zd.laboratory.onemachine.domain.SingInUser;
import com.zd.laboratory.onemachine.domain.SingInViolation;
import com.zd.laboratory.service.*;
import com.zd.system.api.RemoteUserService;
import com.zd.system.api.domain.LabStudentsInfo;
import com.zd.system.api.domain.SysUser;
import com.zd.system.api.exam.RemoteExamService;
import com.zd.system.api.face.FaceCompare;
import com.zd.system.api.face.RemoteFaceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

/**
 * 一体机服务
 *
 * @Author: zhoupan
 * @Date: 2021/09/15/11:05
 * @Description:
 */
@Service
public class OneMachineService implements ValidationSignInPerInfo {

    private static Logger logger = LoggerFactory.getLogger(OneMachineService.class);
    /**
     * 安全准入凭证服务
     */
    @Autowired
    private ILabApprovalService approvalService;
    @Autowired
    private ILabViolationService labViolationService;
    @Autowired
    private ILabBlacklistService blacklistService;
    @Autowired
    private RedisService redisService;
    @Autowired
    private ILabSubjectAccessRecordService subjectAccessRecordService;
    @Autowired
    private ILabPhotoInspectionService labPhotoInspectionService;
    @Autowired
    private LabSubjectSecurityconfigureMapper labSubjectSecurityconfigureMapper;
    @Autowired
    private ILabSubjectService subjectService;
    @Autowired
    private ILabStudentsInfoService studentsInfoService;
    @Autowired
    private RemoteFaceService remoteFaceService;
    @Autowired
    private ILabSubAccessCheckLogService labSubAccessCheckLogService;
    @Autowired
    LabHardwareStateMapper hardwareStateMapper;
    @Autowired
    RemoteExamService remoteExamService;
    @Autowired
    LabSubjectAccessRecordMapper labSubjectAccessRecordMapper;
    @Autowired
    private ILabSecurityApplyService iLabSecurityApplyService;
    @Autowired
    private ILabSecuritySubjectmaterialService iLabSecuritySubjectmaterialService;
    @Autowired
    private ILabWhitelistService iLabWhitelistService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private ILabGradeManageRecordService labGradeManageRecordService;

    private Map<SignEnum, Function<SignInfoVO, SignInPerInfoVO>> validMap;

    @PostConstruct
    public void initValid() {
        validMap = new HashMap<>();
        //签到验证
        validMap.put(SignEnum.SIGN_IN, signInfoVO -> {
            if (signInfoVO == null) {
                SignInPerInfoVO signInPerInfoVO = new SignInPerInfoVO();
                return signInPerInfoVO;
            }
            SignInPerInfoVO signInPerInfoVO = new SignInPerInfoVO(signInfoVO);
            BeanUtils.copyProperties(signInfoVO, signInPerInfoVO);

            //验证
            List<String> messages = new ArrayList<>(3);
            signInPerInfoVO.setMessage(messages);
            //-1 实验室状态时候正常
            LabSubject subject = subjectService.selectLabSubjectById(signInfoVO.getSubId());

            if (subject.getIsDel()) {
                messages.add("实验室当前已禁用，请联系负责人开启！");
            }
            //1、判断是否有安全准入资格，如没有准入资格进行提示(语音+浮层):验证失败，您需要通过小程序申请实验室准入资格后才能签到。
            if(UserConstants.USER_TYPE_STUDENT.equals(signInPerInfoVO.getSingInUser().getType())){
                if (signInPerInfoVO.getSingInUser().getExpirationDate() != null) {
                    if (!signInPerInfoVO.getSingInUser().getExpirationDate().after(DateUtils.getNowDate())) {
                        messages.add("您准入凭证已过期！您需要通过小程序重新申请实验室准入资格后才能签到。");
                    }
                } else {
                    //如果没有找到用户的准入凭证，则需要查询当前实验室是否配置准入凭证
                /*LabSubjectSecurityconfigure subjectSecurityconfigure = new LabSubjectSecurityconfigure();
                subjectSecurityconfigure.setSubjectId(signInfoVO.getSubId());
                List<LabSubjectSecurityconfigure> labSubjectSecurityconfigures = labSubjectSecurityconfigureMapper.selectLabSubjectSecurityconfigureList(subjectSecurityconfigure);
                if (CollUtil.isNotEmpty(labSubjectSecurityconfigures)) {
                    messages.add("您未获取准入凭证！您需要通过小程序申请实验室准入资格后才能签到。");
                }*/
                    //学生签到时 验证是否获取准入凭证
                    /*LabSecuritySubjectmaterial labSecuritySubjectmaterial = new LabSecuritySubjectmaterial();
                    labSecuritySubjectmaterial.setSubjectId(signInfoVO.getSubId());
                    List<LabSecuritySubjectmaterial> list = iLabSecuritySubjectmaterialService.selectLabSecuritySubjectmaterialList(labSecuritySubjectmaterial);
*/
                    //1 获取验证安全准入凭证
                    LabSecurityApplyVO labSecurityApply = new LabSecurityApplyVO();
                    labSecurityApply.setSubjectId(signInfoVO.getSubId());
                    labSecurityApply.setUserId(signInfoVO.getSingInUser().getUserId());
                    labSecurityApply.setAuditStatus(2);
                    List<LabSecurityApplyVO> listapply= iLabSecurityApplyService.selectLabSecurityApplyList(labSecurityApply);
                    if (listapply.size()==0) {
                        messages.add("您未获取准入凭证！您需要通过小程序申请实验室准入资格后才能签到。");
                    }
                }
            }else if("11".equals(signInPerInfoVO.getSingInUser().getType())){

                //教职工登录时 校验白名单是否存在 如果存在退出验证
                LabWhitelistVO labWhitelistVO = new LabWhitelistVO();
                labWhitelistVO.setUserId(signInfoVO.getSingInUser().getUserId());
                labWhitelistVO.setSubId(signInfoVO.getSubId());
                List<LabWhitelist> list = iLabWhitelistService.selectLabWhiteJoinSubList(labWhitelistVO);
                if(list.size()==0){
                    //是否改实验室负责人
                    if(!subject.getAdminId().equals(signInfoVO.getSingInUser().getUserId())){
                        //1 获取验证安全准入凭证
                        LabSecurityApplyVO labSecurityApply = new LabSecurityApplyVO();
                        labSecurityApply.setSubjectId(signInfoVO.getSubId());
                        labSecurityApply.setUserId(signInfoVO.getSingInUser().getUserId());
                        labSecurityApply.setAuditStatus(2);
                        List<LabSecurityApplyVO> listapply= iLabSecurityApplyService.selectLabSecurityApplyList(labSecurityApply);
                        if (listapply.size()==0) {
                            messages.add("您未获取准入凭证！您需要通过小程序申请实验室准入资格后才能签到。");
                        }
                    }
                }
            }

            //todo 获取人脸信息 现在还不确定（已完成）
            //2、判断是否录入人脸，如没有录入人脸进行提示(语音+浮层):验证失败，您需要通过小程序录入人脸后才能签到。
            Long userId = signInfoVO.getSingInUser().getUserId();
            LabStudentsInfo labStudentsInfo = studentsInfoService.selectLabStudentsInfoByJoinStudentsId(userId);

            if (labStudentsInfo == null || labStudentsInfo.getFaceFeature() == null || labStudentsInfo.getFaceFeature().length < 1) {
                messages.add("您需要通过小程序录入人脸后才能签到！");
            }

            //3、判断是否在黑名单里，如在黑名单里进行提示(语音+浮层):验证失败，当前处于违规状态，不能进入实验室，请联系导师处理。。
            LabBlacklist labBlacklist = blacklistService.selectLabBlacklistById(signInfoVO.getSingInUser().getUserId());
            if (labBlacklist != null) {
                messages.add("您当前被禁止进入实验室，请联系导师处理！");
            }
            //4、todo 获取当前是否有未结束的打卡记录, 如果还有未结束的打卡应该告知
            LabSubjectAccessRecordVo sigInAndGet = subjectAccessRecordService.isSigInAndGet(signInfoVO.getSingInUser().getUserId(),signInfoVO.getSubId());
            List<String> tips = new ArrayList<>(1);
            signInPerInfoVO.setTips(tips);
            signInPerInfoVO.setLastSignInError(false);
            if (sigInAndGet != null) {
                signInPerInfoVO.setLastSignInError(true);
                tips.add(StrUtil.format("您当前正在{}打卡，打卡时间：{}", sigInAndGet.getSubjectName(), DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, sigInAndGet.getInTime())));
            }
            for (String msg : messages) {
                logger.error("签入messages：" + msg);
            }
            extracted(signInfoVO, signInPerInfoVO);
            return signInPerInfoVO;

        });
        //签出验证
        validMap.put(SignEnum.SIGN_OUT, signInfoVO -> {
             if (signInfoVO == null) {
                SignInPerInfoVO signInPerInfoVO = new SignInPerInfoVO();
                return signInPerInfoVO;
            }
            SignInPerInfoVO signInPerInfoVO = new SignInPerInfoVO(signInfoVO);
            BeanUtils.copyProperties(signInfoVO, signInPerInfoVO);
            List<String> tips = new ArrayList<>(1);
            signInPerInfoVO.setTips(tips);
            //验证信息
            List<String> messages = new ArrayList<>(1);
            signInPerInfoVO.setMessage(messages);
            //是否有正常签到记录
//            Boolean sigIn = subjectAccessRecordService.isSigIn(signInfoVO.getSubId(), signInfoVO.getSingInUser().getUserId());

            LabSubjectAccessRecordVo sigInAndGet = subjectAccessRecordService.isSigInAndGet(signInfoVO.getSingInUser().getUserId(),signInfoVO.getSubId());

            //-1 实验室状态
            LabSubject subject = subjectService.selectLabSubjectById(signInfoVO.getSubId());
            //先判断实验室状态,再判断其他的验证信息
            if (subject == null) {
                messages.add("签到实验室不存在！");
            } else if (subject.getIsDel()) {
                messages.add("实验室当前已禁用，暂停签到&签出！。");
            } else {
                if (sigInAndGet == null) {
                    messages.add("您当前实验室没有签到记录，或距上次签到已超过24小时！");
                } else if (!signInfoVO.getSubId().equals(sigInAndGet.getSubjectId())) {
                    messages.add("您当前实验室没有签到记录，或距上次签到已超过24小时！");
                } else {
                    //是否有拍照检查记录
                    LabPhotoInspection labPhotoInspection = labPhotoInspectionService.selectLabPhotoInspectionById(sigInAndGet.getId());
                    // TODO 白向玉 92612 不需要签到和签出验证
                    if (labPhotoInspection == null && signInfoVO.getSingInUser().getUserId() != 92612) {
                        //检验实验室是否配置了检查项，如果没有，直接签退离开
                        if(StringUtils.isEmpty(subject.getCheckOut())){
                            subjectAccessRecordService.out(subject.getId(), signInfoVO.getSingInUser().getUserId());
                        }else{
                            messages.add("请在小程序上完成拍照检查再离开实验室！");
                        }
                    }else {
                        // 白老师此处直接签退
                        subjectAccessRecordService.out(subject.getId(), signInfoVO.getSingInUser().getUserId());
                    }

//                    //学生登陆时 给奖励分
//                    SysUser sysUser = tokenService.getLoginUser().getSysUser();
//                    if(UserConstants.USER_TYPE_STUDENT.equals(sysUser.getUserType())){
//                        Map map = new HashMap();
//                        map.put("userId", signInfoVO.getSingInUser().getUserId());
//                        map.put("status", "1");
//                        R r = remoteExamService.addLoginfo(map);
//                        if (r.getCode() != 200) {
//                            logger.info("打卡签出奖励分记录保存失败！");
//                        }
//                    }
//                    else
//                    {
//                        tips.add("请在小程序上完成拍照检查再离开实验室！");
//                    }
                }
            }
            extracted(signInfoVO, signInPerInfoVO);
            return signInPerInfoVO;
        });
    }

    /**
     * 保存验证码
     *
     * @param signInfoVO
     * @param signInPerInfoVO
     */
    private void extracted(SignInfoVO signInfoVO, SignInPerInfoVO signInPerInfoVO) {
        logger.error("************进入extracted***************");
        if (CollUtil.isEmpty(signInPerInfoVO.getMessage())) {
            // 保存验证码信息
            String uuid = IdUtils.simpleUUID();
            String verifyKey = getVerifyKey(signInfoVO.getSubId(), uuid);
            //有效期1分钟
            saveVerify(signInfoVO, verifyKey);
            logger.error("***************************" + verifyKey);
            signInPerInfoVO.setCode(uuid + "_" + signInfoVO.getSubId());
            signInPerInfoVO.setState(Boolean.TRUE);
        }
        signInPerInfoVO.setState(Boolean.FALSE);
        logger.error("************退出extracted***************");
    }

    private String getVerifyKey(Long subid, String uuid) {
        return Constants.SINGIN_CAPTCHA_CODE_KEY + uuid + "_" + subid;
    }

    private void saveVerify(SignInfoVO signInfoVO, String verifyKey) {
        logger.error("signInfoVO.getSingInUser()" + signInfoVO.getSingInUser().getNickName());
        redisService.setCacheObject(verifyKey, signInfoVO.getSingInUser(), 5L, TimeUnit.MINUTES);
    }


    /**
     * 用户服务
     */
    @Autowired
    RemoteUserService userService;

    /**
     * 提交签到（人脸）/签出记录
     *
     * @param code     验证码
     * @param signEnum 签到类型
     * @param face     人脸特征码
     * @return
     */
    public ResultData postSign(String code, SignEnum signEnum, byte[] face) {
        try {
            logger.info("&&&&&&&&&&&&&&&&&&&&&&" + code + "," + signEnum);
            if (StringUtils.isEmpty(code)) {
                //            throw new CaptchaException("签到验证码错误，请重新刷卡重试！");
                ResultData.fail(600, "签到验证码错误，请重新刷卡重试！");
            }
            String verifyKey = Constants.SINGIN_CAPTCHA_CODE_KEY + code;
            SingInUser user = redisService.getCacheObject(verifyKey);
            if (user == null || user.getUserId() == null) {
                ResultData.fail(600, "签到&签出人脸已超时，请重新刷卡重试！");
            }
//            boolean expire = redisService.expire(verifyKey, 120);
//            if (!expire) return ResultData.fail(600, "签到&签出验证码已超时，请重新刷卡重试！");
            if (user != null) {
                String s = StrUtil.subAfter(code, "_", true);
                if (signEnum.equals(SignEnum.SIGN_IN)) {

                    logger.info("1111111签到调用人脸服务");
                    //调用人脸验证
                    R r = faceCompare(user.getUserId(), face);
                    //验证失败刷新验证码时间
                    if (r.getCode() != 200) {
                        return ResultData.fail(r.getMsg());
                    }
                    logger.info("2222222人脸服务调用完成！");

                    //插入进入实验室记录
                    LabSubjectAccessRecordVo subjectAccessRecord = new LabSubjectAccessRecordVo();
                    subjectAccessRecord.setDeptId(user.getDeptId());
                    subjectAccessRecord.setSubjectId(Long.parseLong(s));
                    subjectAccessRecord.setJoinUserId(user.getUserId());

                    long l = subjectAccessRecordService.leaveAgainSign(subjectAccessRecord);
                    //
                    if (l > 0) {
                        redisService.deleteObject(verifyKey);
                        //增加一个key 用记录ID作为key，值是实验室ID 有效期两分钟
                        redisService.setCacheObject(Constants.SINGIN_id_KEY + subjectAccessRecord.getId(), Long.parseLong(s), 2L, TimeUnit.MINUTES);
                    }else{
                        return ResultData.fail("当前用户已经签到成功，不能重复签到。");
                    }

                    //学生登陆时 给奖励分
                    if(UserConstants.USER_TYPE_STUDENT.equals(user.getType())){
                        Map map = new HashMap();
                        map.put("userId", user.getUserId());
                        map.put("status", "0");
                       r = remoteExamService.addLoginfo(map);
                        if (r.getCode() != 200) {
                            logger.info("打卡签到奖励分记录保存失败！");
                            // throw new ServiceException("打卡签出奖励分记录保存失败！");
                        }
                    }

                    // 用户签到成功检测有无管控工作，有则发起通知
                    labGradeManageRecordService.sendManageMsgBySiginUser(user.getUserId(), Long.parseLong(s));

                    logger.info("333333用户签到完成！");
                    return ResultData.result(subjectAccessRecord.getId());
                } else if (signEnum.equals(SignEnum.SIGN_OUT)) {
                    redisService.deleteObject(verifyKey);
//                    return ResultData.result(subjectAccessRecordService.out(Long.parseLong(s), user.getUserId()));
                    subjectAccessRecordService.out(Long.parseLong(s), user.getUserId());
//                    LabSubjectAccessRecord subjectAccessRecord = new LabSubjectAccessRecord();
//                    subjectAccessRecord.setSubjectId(Long.parseLong(s));
//                    user.setUserId(subjectAccessRecord.getUserId());
//                    LabSubjectAccessRecord labSubjectAccessRecord= labSubjectAccessRecordMapper.queryLastByUserId(subjectAccessRecord);
//                    if(null==labSubjectAccessRecord){
//                        ResultData.fail("未查到离开签到记录，请联系管理员！");
//                    }

                    //学生登陆时 给奖励分
//                    SysUser sysUser = tokenService.getLoginUser().getSysUser();
                    if(UserConstants.USER_TYPE_STUDENT.equals(user.getType())){
                        Map map = new HashMap();
                        map.put("userId", user.getUserId());
                        map.put("status", "1");
//                    map.put("subId",labSubjectAccessRecord.getSubjectId());
//                    map.put("inTime",labSubjectAccessRecord.getInTime());
//                    map.put("outTime",labSubjectAccessRecord.getOutTime());
                        R r = remoteExamService.addLoginfo(map);
                        if (r.getCode() != 200) {
                            logger.info("打卡签出奖励分记录保存失败！");
                            // throw new ServiceException("打卡签出奖励分记录保存失败！");
                        }
                    }
                    return ResultData.result(true);
                }
            }
        } catch (Exception e) {
            e.getStackTrace();
        }
        return ResultData.fail();
    }

    /**
     * @param id
     * @return
     */
    public ResultData commitSign(Long id) {
        String key = Constants.SINGIN_id_KEY + id;
        Long subId = redisService.getCacheObject(key);
        if (subId == null) return ResultData.fail(600, "签到已超时,请重新刷卡重试！");
        //获取实验室配置的签到检查项
        LabSubject subject = subjectService.selectLabSubjectById(subId);
        Assert.isNotNull(subject, "实验室不存在");

        // 如果是白老师证号则不校验
        LabSubjectAccessRecord record = subjectAccessRecordService.selectLabSubjectAccessRecordById(id);
        if(record != null && record.getJoinUserId() != null && record.getJoinUserId() != 92612){
            Optional.ofNullable(subject.getCheckIn())
                    .filter(a -> StrUtil.isNotBlank(a))
                    .ifPresent(a -> {
                        String[] split = a.split(",");
                        //获取检查记录
                        List<String> strings = labSubAccessCheckLogService.selectSuccessTypeBySignId(id);
                        if (CollUtil.isEmpty(strings) || strings.size() != split.length) {
                            throw new ServiceException("未完成全部检查记录！");
                        }
                        Arrays.stream(split).filter(b -> !strings.contains(b)).findFirst().ifPresent(b -> {
                            throw new ServiceException("未完成全部检查记录！");
                        });
                    });
        }

        //更新签到记录
        boolean b = subjectAccessRecordService.updateCheck(id);
        if (!b) {
            throw new ServiceException("更新签到记录失败！！");
        }
        //删除key
        redisService.deleteObject(key);
        //return ResultData.success(true);
        LabSubjectAccessRecord labSubjectAccessRecord = subjectAccessRecordService.selectLabSubjectAccessRecordById(id);
        if (null == labSubjectAccessRecord) {
            throw new ServiceException("查询签到记录失败！！");
        }
//        //删除key
//        //redisService.deleteObject(key);

        return ResultData.success(true);
    }

    public R faceCompare(Long userId, byte[] face) {

        FaceCompare faceCompare = new FaceCompare();
        faceCompare.setUserId(userId);
        faceCompare.setData(face);
        R compare = remoteFaceService.compare(faceCompare);

        return compare;
    }

    /**
     * 创建签到对象
     *
     * @param subId
     * @param user
     * @return
     */
    @Override
    public SignInPerInfoVO createSignInPerInfoVO(Long subId, SysUser user, SignEnum signEnum) {

        /*SignInfoVO signInPerInfoVO = getSignInPerInfoVO(subId, user);
        Function<SignInfoVO, SignInPerInfoVO> signInfoVOSignInPerInfoVOFunction = validMap.get(signEnum);
        Assert.isNotNull(signInfoVOSignInPerInfoVOFunction, "不存在的签到类型！");
        return signInfoVOSignInPerInfoVOFunction.apply(signInPerInfoVO);*/

        SignInfoVO signInPerInfoVO = getSignInPerInfoVO(subId, user);
        Function<SignInfoVO, SignInPerInfoVO> signInfoVOSignInPerInfoVOFunction = validMap.get(signEnum);
        Assert.isNotNull(signInfoVOSignInPerInfoVOFunction, "不存在的签到类型！");
        return signInfoVOSignInPerInfoVOFunction.apply(signInPerInfoVO);

    }

    /**
     * 获取签到验证对象
     *
     * @param subId
     * @param user
     * @return
     */
    private SignInfoVO getSignInPerInfoVO(Long subId, SysUser user) {

        /*if (user == null) return null;

        //todo 现在是串行处理， 影响大的话可以改为异步处理
        //1 获取验证安全准入凭证
        List<LabApprovalVO> labApprovals = getLabApprovals(subId, user);
        SingInUser singInUser = new SingInUser(user, labApprovals);
        //2查询最新一条违约记录
        SingInViolation singInViolation = extracted(user);
        SignInfoVO signInPerInfoVO = new SignInfoVO(singInUser, singInViolation);
        signInPerInfoVO.setSubId(subId);
        return signInPerInfoVO;*/

        //2.3签到
        if (user == null) return null;
        //1 获取验证安全准入凭证
        LabSecurityApplyVO labSecurityApply = new LabSecurityApplyVO();
        labSecurityApply.setSubjectId(subId);
        labSecurityApply.setUserId(user.getUserId());
        labSecurityApply.setAuditStatus(2);
        List<LabSecurityApplyVO> listapply= iLabSecurityApplyService.selectLabSecurityApplyList(labSecurityApply);

        SingInUser singInUser = new SingInUser(user, listapply);
        if(listapply.size()==0){
            singInUser.setType(user.getUserType());
        }
        //2查询最新一条违约记录
        SingInViolation singInViolation = extracted(user);
        SignInfoVO signInPerInfoVO = new SignInfoVO(singInUser, singInViolation);
        signInPerInfoVO.setSubId(subId);
        return signInPerInfoVO;
    }

    private SingInViolation extracted(SysUser user) {
        LabViolationDTO violation = new LabViolationDTO();
        violation.setSize(1);
        violation.setJoinUserId(user.getUserId());
        List<LabViolationVO> labViolationVOS = labViolationService.selectMyLabViolationVOList(violation);
        return new SingInViolation(labViolationVOS);
    }

    private List<LabApprovalVO> getLabApprovals(Long subId, SysUser user) {
        LabApproval labApproval = new LabApproval();
        labApproval.setJoinUserId(user.getUserId());
        labApproval.setSubjectId(subId);
        List<LabApprovalVO> labApprovals = approvalService.selectLabApprovalList(labApproval);
        return labApprovals;
    }

    /**
     * 2.3 安全准入凭证查询
     * @param subId
     * @param user
     * @return
     */
    private List<LabSecurityApplyVO> getLabApply(Long subId, SysUser user) {
        LabSecurityApplyVO labApply = new LabSecurityApplyVO();
        labApply.setUserId(user.getUserId());
        labApply.setSubjectId(subId);
        List<LabSecurityApplyVO> labApplyList = iLabSecurityApplyService.selectLabSecurityApplyList(labApply);
        return labApplyList;
    }

    /**
     * 查询实验室人员信息
     * 实验室id subId
     */
    public List<SysUser> querySubOnlineUser(Map<String, Object> params) {
        return hardwareStateMapper.querySubOnlineUserByOnepc(params);
    }
}
