package com.zd.laboratory.service.impl;

import java.util.*;

import com.alibaba.fastjson.JSON;
import com.zd.common.core.domain.R;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.exception.ServiceException;
import com.zd.common.core.utils.*;
import com.zd.common.datascope.annotation.DataScope;
import com.zd.common.security.service.TokenService;
import com.zd.common.security.utils.SaveUtil;
import com.zd.laboratory.domain.LabBlackdetail;
import com.zd.laboratory.domain.dto.LabBlacklistDTO;
import com.zd.laboratory.domain.vo.ElPassConfigdetailVO;
import com.zd.laboratory.domain.vo.LabBlackdetailVO;
import com.zd.laboratory.domain.vo.LabBlacklistVO;
import com.zd.laboratory.mapper.LabBlackdetailMapper;
import com.zd.laboratory.mapper.LabMessageContentMapper;
import com.zd.laboratory.service.ILabViolationService;
import com.zd.system.api.exam.RemoteExamService;
import com.zd.system.api.face.factory.RemoteFaceFallbackFactory;
import com.zd.system.api.laboratory.RemoteLaboratoryService;
import com.zd.system.api.laboratory.domain.LabMessageContent;
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 com.zd.laboratory.mapper.LabBlacklistMapper;
import com.zd.laboratory.domain.LabBlacklist;
import com.zd.laboratory.service.ILabBlacklistService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 黑名单Service业务层处理
 *
 * @author zd
 * @date 2021-09-01
 */
@Service
public class LabBlacklistServiceImpl implements ILabBlacklistService {
    @Autowired
    private LabBlacklistMapper labBlacklistMapper;
    @Autowired
    private LabBlackdetailMapper labBlackdetailMapper;
    @Autowired
    private RemoteExamService remoteExamService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private LabMessageContentMapper labMessageContentMapper;
    @Autowired
    private ILabViolationService iLabViolationService;

    private static final Logger log = LoggerFactory.getLogger(LabBlacklistServiceImpl.class);

    /**
     * 设置黑名单用户
     *
     * @param labBlacklist 黑名单信息
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public Boolean setBackUser(LabBlacklist labBlacklist) {
        //判断是否已有黑名单
        //todo 该判断方式 并发时存在问题
        LabBlacklist labBlacklist1 = selectLabBlacklistById(labBlacklist.getJoinUserId());
        Assert.isNull(labBlacklist1, "黑名单已存在不能重复添加");
        //添加
        return insertLabBlacklist(labBlacklist) == 1;
    }

    /**
     * 查询黑名单列表
     *
     * @param labBlacklist 黑名单
     * @return 黑名单集合
     */
    @DataScope(deptAlias = "t", permi = PerPrefix.LABORATORY_BLACKLIST)
    public List<LabBlacklistVO> selectLabBlackVOList(LabBlacklistDTO labBlacklist) {
        return labBlacklistMapper.selectLabBlackVOList(labBlacklist);
    }

    /**
     * 查询黑名单
     *
     * @param id 黑名单主键
     * @return 黑名单
     */
    @Override
    public LabBlacklist selectLabBlacklistById(Long id) {
        return labBlacklistMapper.selectLabBlacklistById(id);
    }

    /**
     * 查询黑名单列表
     *
     * @param labBlacklist 黑名单
     * @return 黑名单
     */
    @Override
    public List<LabBlacklist> selectLabBlacklistList(LabBlacklist labBlacklist) {
        return labBlacklistMapper.selectLabBlacklistList(labBlacklist);
    }


    /**
     * 根据用户查询是否在黑名单
     *
     * @param labBlacklist 根据用户查询是否在黑名单
     * @return boolean
     */
    @Override
    public boolean getUserBoolean(LabBlacklistDTO labBlacklist) {
        List<LabBlacklist> labBlacklists = labBlacklistMapper.selectLabBlacklistList(labBlacklist);
        if(labBlacklists.size()>0){
            LabBlacklist blacklist = labBlacklists.get(0);
            if(blacklist.getBlacklistStatus()==1){
                return true;
            }
        }
        return false;
    }

    /**
     * 新增黑名单
     *
     * @param labBlacklist 黑名单
     * @return 结果
     */
    @Override
    public int insertLabBlacklist(LabBlacklist labBlacklist) {
        labBlacklist.setCreateTime(DateUtils.getNowDate());
        labBlacklist.setBlacklistStatus(1);
        labBlacklist.setCreateBy(SecurityUtils.getUsername());
        labBlacklist.setDeptId(SpringUtils.getBean(TokenService.class).getLoginUser().getSysUser().getDeptId());
        labBlacklist.setDeptName(SpringUtils.getBean(TokenService.class).getLoginUser().getSysUser().getDeptName());
        return labBlacklistMapper.insertLabBlacklist(labBlacklist);
    }

    /**
     * 修改黑名单
     *
     * @param labBlacklist 黑名单
     * @return 结果
     */
    @Override
    public int updateLabBlacklist(LabBlacklist labBlacklist) {
        labBlacklist.setUpdateTime(DateUtils.getNowDate());
        labBlacklist.setUpdateBy(SecurityUtils.getUsername());
        return labBlacklistMapper.updateLabBlacklist(labBlacklist);
    }


    /**
     * 新增黑名单
     *
     * @param labBlacklistVO 黑名单
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addBlacklist(LabBlacklistVO labBlacklistVO) {
        Map<String,Object> markconfigMap = new HashMap<>();
        R<Object> data = remoteExamService.getPointsConfig(markconfigMap);
        int flag=0;
        if (data!=null) {
            String code = data.getCode()+"";
            if(code.equals("200")){
                Map<String,Object> pointsConfig = (Map <String, Object>) data.getData();
                //获取积分详情列表
                List<Map<String,Object>> pointsConfigDetail = (List <Map <String, Object>>) pointsConfig.get("configDetailList");
                //查询userid，是不是之前已经有进入过黑名单记录，没有需要新增，有则查回来修改。
                LabBlacklist userBlack = labBlacklistMapper.selectLabBlacklistByUserId(labBlacklistVO.getJoinUserId());
                if(userBlack!=null){
                    //修改黑名单用户列表信息
                    LabBlacklist userBlackNew = new LabBlacklist();
                    userBlackNew.setId(userBlack.getId());
                    userBlackNew.setBlacklistStatus(1);
                    userBlackNew.setJoinUserId(userBlack.getJoinUserId());
                    userBlackNew.setReason(labBlacklistVO.getReason());
                    userBlackNew.setCreditScore(labBlacklistVO.getCreditScore());
//                    if(StringUtils.isNotNull(tokenService.getLoginUser())){
//                        userBlackNew.setUpdateBy(tokenService.getLoginUser().getSysUser().getNickName());
//                    }else{
//                    userBlackNew.setUpdateBy("系统用户");
//                    }
                    if(!labBlacklistVO.getFlagAction()){
                        if(tokenService.getLoginUser()!=null){
                            userBlackNew.setUpdateBy(tokenService.getLoginUser().getNickName());
                        }else{
                            userBlackNew.setUpdateBy("系统");
                        }
                    }else{
                        userBlackNew.setUpdateBy("系统");
                    }

                    userBlackNew.setUpdateTime(new Date());
                    labBlacklistMapper.updateLabBlacklist(userBlackNew);
                    //循环判断积分匹配规则
                    ElPassConfigdetailVO passConfigdetailVO = getIntegralMatchingRules(pointsConfigDetail,Integer.parseInt(labBlacklistVO.getSurplusCreditScore()));
                    //处理黑名单日志方法
                    flag = handleBlackDetail(passConfigdetailVO,userBlackNew,labBlacklistVO.getSurplusCreditScore(),labBlacklistVO.getFlagAction());
                    return flag;
                }else{
                    //插入黑名单列表
                    LabBlacklist labBlacklistNew = new LabBlacklist();
                    labBlacklistNew.setJoinUserId(labBlacklistVO.getJoinUserId());
                    labBlacklistNew.setBlacklistStatus(1);
                    labBlacklistNew.setReason(labBlacklistVO.getReason());
                    //设置其他公共字段
//                    SaveUtil.setCommonAttr(labBlacklistNew);
//                    labBlacklistNew.setCreateBy("系统用户");
                    if(!labBlacklistVO.getFlagAction()){
                        if(tokenService.getLoginUser()!=null){
                            labBlacklistNew.setCreateBy(tokenService.getLoginUser().getNickName());
                        }else{
                            labBlacklistNew.setCreateBy("系统");
                        }
                    }else{
                        labBlacklistNew.setCreateBy("系统");
                    }

                    labBlacklistNew.setCreateTime(new Date());
                    labBlacklistNew.setCreditScore(labBlacklistVO.getCreditScore());
                    labBlacklistMapper.insertLabBlacklist(labBlacklistNew);

                    //循环判断积分匹配规则
                    ElPassConfigdetailVO passConfigdetailVO = getIntegralMatchingRules(pointsConfigDetail,Integer.parseInt(labBlacklistVO.getSurplusCreditScore()));
                    //处理黑名单日志方法
                    flag = handleBlackDetail(passConfigdetailVO,labBlacklistNew,labBlacklistVO.getSurplusCreditScore(),labBlacklistVO.getFlagAction());
                    return flag;
                }
            }
        }

        return flag;
    }

    //处理黑名单日志方法
    public int handleBlackDetail(ElPassConfigdetailVO passConfigdetailVO,LabBlacklist labBlacklistNew,String surplusCreditScore,Boolean flagAction){
        if(passConfigdetailVO.getId()!=null){
            LabBlackdetail blackdetail = new LabBlackdetail();
            blackdetail.setBlackId(labBlacklistNew.getId());
            blackdetail.setReason(labBlacklistNew.getReason());
            if(blackdetail.getTreatmentMethod()==null){
                blackdetail.setTreatmentMethod("");
            }
            //警告消息通知
            if(passConfigdetailVO.getWarningStatus()==1){
                //这里需要通知警告
                LabMessageContent labMessageContent = new LabMessageContent();
//                labMessageContent.setSendMode(1);
                labMessageContent.setSendRange(3);
                labMessageContent.setMessClass(1);
                labMessageContent.setContent("您由于多次违规，现已将你移入到黑名单，如需解除，需要根据黑名单规定，参加指定学习！！");
                labMessageContent.setUserIds(labBlacklistNew.getJoinUserId()+"");
                labMessageContent.setUserId(-2L);
                labMessageContent.setCreateTime(new Date());
//                labMessageContent.setCreateBy("系统用户");
                if(!flagAction) {
                    if (tokenService.getLoginUser() != null) {
                        labMessageContent.setCreateBy(tokenService.getLoginUser().getNickName());
                    } else {
                        labMessageContent.setCreateBy("系统");
                    }
                }else{
                    labMessageContent.setCreateBy("系统");
                }
                labMessageContentMapper.insertLabMessageContent(labMessageContent);
                blackdetail.setTreatmentMethod(blackdetail.getTreatmentMethod()+"警告,");
            }
            //约谈通知
            if(passConfigdetailVO.getInterviewStatus()==1){
                //这里需要约谈通知，具体需不需要保存字段，等周一讨论
                LabMessageContent labMessageContent = new LabMessageContent();
//                labMessageContent.setSendMode(1);
                labMessageContent.setSendRange(3);
                labMessageContent.setMessClass(1);
                labMessageContent.setContent("您由于违规，需要联系实验室老师进行沟通！！");
                labMessageContent.setUserIds(labBlacklistNew.getJoinUserId()+"");
                labMessageContent.setUserId(-2L);
                labMessageContent.setCreateTime(new Date());
//                labMessageContent.setCreateBy("系统用户");
                if(!flagAction) {
                    if (tokenService.getLoginUser() != null) {
                        labMessageContent.setCreateBy(tokenService.getLoginUser().getNickName());
                    } else {
                        labMessageContent.setCreateBy("系统");
                    }
                }else{
                    labMessageContent.setCreateBy("系统");
                }
                labMessageContentMapper.insertLabMessageContent(labMessageContent);
                blackdetail.setTreatmentMethod(blackdetail.getTreatmentMethod()+"约谈,");
            }
            //学习状态
            if(passConfigdetailVO.getLearnStatus()==1){
                blackdetail.setLearnStatus(0);
                blackdetail.setTreatmentMethod(blackdetail.getTreatmentMethod()+"学习,");
                //处理小时和分钟，计算成秒
                blackdetail.setLearnTime(passConfigdetailVO.getLearnHour()*60*60+passConfigdetailVO.getLearnMinute()*60);
            }
            //考试状态
            if(passConfigdetailVO.getTestStatus()==1){
                blackdetail.setTestStatus(0);
                blackdetail.setTreatmentMethod(blackdetail.getTreatmentMethod()+"考试,");
            }
            //做题状态
            if(passConfigdetailVO.getPracticeStatus()==1){
                blackdetail.setPracticeStatus(0);
                blackdetail.setTreatmentMethod(blackdetail.getTreatmentMethod()+"做题,");
                blackdetail.setNumberTopics(passConfigdetailVO.getNumberTopics());
                blackdetail.setNumberAccuracy(passConfigdetailVO.getNumberAccuracy());
            }
            //处理多余的，号
            if(blackdetail.getTreatmentMethod()!=null && !"".equals(blackdetail.getTreatmentMethod())){
                blackdetail.setTreatmentMethod(blackdetail.getTreatmentMethod().substring(0,blackdetail.getTreatmentMethod().length()-1));
            }
            blackdetail.setOverStatus(0);
            blackdetail.setHandleDay(getExpireDate(passConfigdetailVO.getHandleDay()));
            blackdetail.setCreditScore(Long.parseLong(labBlacklistNew.getCreditScore()));
            //设置其他公共字段
//            SaveUtil.setCommonAttr(blackdetail);
//            blackdetail.setCreateBy("系统用户");
            if(!flagAction) {
                if(tokenService.getLoginUser()!=null){
                    blackdetail.setCreateBy(tokenService.getLoginUser().getNickName());
                }else{
                    blackdetail.setCreateBy("系统");
                }
            }else{
                blackdetail.setCreateBy("系统");
            }

            blackdetail.setCreateTime(new Date());
            blackdetail.setSurplusCreditScore(surplusCreditScore);
            return labBlackdetailMapper.insertLabBlackdetail(blackdetail);
        }else{
            LabBlackdetail blackdetail = new LabBlackdetail();
            blackdetail.setBlackId(labBlacklistNew.getId());
            blackdetail.setReason(labBlacklistNew.getReason());
            //设置其他公共字段
//            SaveUtil.setCommonAttr(blackdetail);
//            blackdetail.setCreateBy("系统用户");
            if(!flagAction) {
                if(tokenService.getLoginUser()!=null){
                    blackdetail.setCreateBy(tokenService.getLoginUser().getNickName());
                }else{
                    blackdetail.setCreateBy("系统");
                }
            }else{
                blackdetail.setCreateBy("系统");
            }

            blackdetail.setCreateTime(new Date());
            blackdetail.setCreditScore(Long.parseLong(labBlacklistNew.getCreditScore()));
            blackdetail.setSurplusCreditScore(surplusCreditScore);
            return labBlackdetailMapper.insertLabBlackdetail(blackdetail);
        }
    }

    public Date getExpireDate(Integer handleDay){
        //计算到期时间
        Date date=new   Date();//取时间
        Calendar   calendar   =   new   GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,handleDay);//把日期往后增加一天.整数往后推,负数往前移动
        date=calendar.getTime();   //这个时间就是日期往后推一天的结果
        return date;
    }


    //匹配积分规则方法
    public ElPassConfigdetailVO getIntegralMatchingRules(List<Map<String,Object>> pointsConfigDetail,Integer creditScore){
        ElPassConfigdetailVO passConfigdetailVO = new ElPassConfigdetailVO();
        Optional.ofNullable(pointsConfigDetail).orElseGet(Collections::emptyList).stream().forEach(a->{
            Integer beginScore = Integer.parseInt(a.get("beginScore")+"");
            Integer endScore = Integer.parseInt(a.get("endScore")+"");
            if(beginScore<creditScore && creditScore<=endScore){
                ElPassConfigdetailVO passConfigdetail = JSON.parseObject(JSON.toJSONString(a),ElPassConfigdetailVO.class);
                BeanUtils.copyProperties(passConfigdetail,passConfigdetailVO);
            }
        });
        return passConfigdetailVO;
    }

    //黑名单完成学习规则
    @Override
    public int blacklistCompletionLearningRules(LabBlackdetailVO blackdetailVO){
        int flag = 0;
        LabBlacklist labBlack =  this.selectLabBlacklistById(blackdetailVO.getJoinUserId());
        if(labBlack!=null && labBlack.getBlacklistStatus()==1){
            LabBlackdetail labBlackdetail = labBlackdetailMapper.selectLabBlackdetailByBlackId(labBlack.getId());
            LabBlackdetail labBlackdetailNew = new LabBlackdetail();
            if(blackdetailVO.getLearnStatus()!=null && blackdetailVO.getLearnStatus()==labBlackdetail.getLearnStatus()){
                if(blackdetailVO.getLearnTime()>=labBlackdetail.getLearnTime()){
                    labBlackdetailNew.setLearnStatus(1);
                    labBlackdetailNew.setId(labBlackdetail.getId());
                }
            }
            if(blackdetailVO.getTestStatus()!=null && blackdetailVO.getTestStatus()==labBlackdetail.getTestStatus()){
                labBlackdetailNew.setTestStatus(1);
                labBlackdetailNew.setId(labBlackdetail.getId());
            }
            if(blackdetailVO.getPracticeStatus()!=null && blackdetailVO.getPracticeStatus()==labBlackdetail.getPracticeStatus()){
                if(blackdetailVO.getNumberTopics()>=labBlackdetail.getNumberTopics()){
                    if(blackdetailVO.getNumberAccuracy()>=labBlackdetail.getNumberAccuracy()){
                        labBlackdetailNew.setPracticeStatus(1);
                        labBlackdetailNew.setId(labBlackdetail.getId());
                    }
                }
            }
            if(labBlackdetailNew.getId()!=null){
                labBlackdetailNew.setUpdateBy("系统执行");
                labBlackdetailNew.setUpdateTime(new Date());
                labBlackdetailMapper.updateLabBlackdetail(labBlackdetailNew);
            }

            overBlackLearn(labBlack.getId(),blackdetailVO.getJoinUserId());
            flag = 200;
        }
        return flag;
    }


    public void overBlackLearn(Long blackId,Long joinUserId){

        LabBlackdetail labBlackdetail = labBlackdetailMapper.selectLabBlackdetailByBlackId(blackId);
        if(labBlackdetail!=null && labBlackdetail.getOverStatus()==0){
            int maxCount = 0;
            int nowCount = 0;
            if(labBlackdetail.getLearnStatus()!=-1){
                if(labBlackdetail.getLearnStatus()==1){
                    nowCount++;
                }
                maxCount++;
            }
            if(labBlackdetail.getTestStatus()!=-1){
                if(labBlackdetail.getTestStatus()==1){
                    nowCount++;
                }
                maxCount++;
            }
            if(labBlackdetail.getPracticeStatus()!=-1){
                if(labBlackdetail.getPracticeStatus()==1){
                    nowCount++;
                }
                maxCount++;
            }
            if(maxCount!=0){
                if(nowCount==maxCount){
                    LabBlackdetail labBlackdetailNew = new LabBlackdetail();
                    labBlackdetailNew.setId(labBlackdetail.getId());
                    labBlackdetailNew.setOverStatus(1);
                    labBlackdetailNew.setUpdateBy("系统执行");
                    labBlackdetailNew.setUpdateTime(new Date());
                    labBlackdetailMapper.updateLabBlackdetail(labBlackdetailNew);

                    LabBlacklist labBlacklist = new LabBlacklist();
                    labBlacklist.setJoinUserId(joinUserId);
                    labBlacklist.setReason("完成规定内容:"+labBlackdetail.getTreatmentMethod()+",系统自动复原信用分.");
                    removeBlacklist(labBlacklist);
                }
            }

        }
    }

    /**
     * 移除黑名单
     *
     * @param labBlacklist 移除黑名单
     * @return 结果
     */
    @Override
    public int removeBlacklist(LabBlacklist labBlacklist) {
        int flag = 500;
        //给积分管理，写入对应的内容
        LabBlacklist userBlack = labBlacklistMapper.selectLabBlacklistById(labBlacklist.getJoinUserId());
        if(StringUtils.isNotNull(userBlack)){
            Map<String,Object> recoveryMap = new HashMap<>();
            recoveryMap.put("joinUserId",userBlack.getJoinUserId()+"");
            recoveryMap.put("pointsType","1");
            recoveryMap.put("reason","手动恢复黑名单"+labBlacklist.getReason());
            R <Object> data = remoteExamService.recoveryPoints(recoveryMap);
            if (data!=null) {
                String code = data.getCode()+"";
                if(code.equals("200")){
                    LabBlacklist labBlacklistNew = new LabBlacklist();
                    //修改黑名单状态
                    labBlacklistNew.setJoinUserId(labBlacklist.getJoinUserId());
                    labBlacklistNew.setUpdateTime(DateUtils.getNowDate());
                    labBlacklistNew.setUpdateBy(SecurityUtils.getUsername());
                    labBlacklistNew.setBlacklistStatus(0);
                    flag = labBlacklistMapper.updateLabBlacklist(labBlacklistNew);
                    //移除黑名单，需要变更详细表考试状态为已恢复。
                    LabBlackdetailVO blackdetailVO = new LabBlackdetailVO();
                    blackdetailVO.setBlackId(userBlack.getId());
                    List<LabBlackdetailVO> labBlackdetailVOList = labBlackdetailMapper.selectLabBlackdetailList(blackdetailVO);
                    int limit = 0;
                    for(LabBlackdetailVO labBlackdetailVO:labBlackdetailVOList){
                        if(limit==1){
                            break;
                        }
                        if(labBlackdetailVO.getLearnStatus().equals(0)){
                            labBlackdetailVO.setLearnStatus(2);
                        }
                        if(labBlackdetailVO.getTestStatus().equals(0)){
                            labBlackdetailVO.setTestStatus(2);
                        }
                        if(labBlackdetailVO.getPracticeStatus().equals(0)){
                            labBlackdetailVO.setPracticeStatus(2);
                        }
                        labBlackdetailVO.setUserId(null);
                        labBlackdetailVO.setOverStatus(1);
                        labBlackdetailMapper.updateLabBlackdetail(labBlackdetailVO);
                        limit++;
                    }
                    //这里调用刘吉焕的移除负面清单方法
                    iLabViolationService.resetUserStatus(labBlacklist.getJoinUserId(),labBlacklist.getReason());
                }
            }
        }else{
            //这里调用刘吉焕的移除负面清单方法
            iLabViolationService.resetUserStatus(labBlacklist.getJoinUserId(),labBlacklist.getReason());
        }

        return flag;
    }



    /**
     * 移除黑名单
     *
     * @param labBlacklist 移除黑名单
     * @return 结果
     */
    @Override
    public int removeBlacklistByPc(LabBlacklist labBlacklist) {
        int flag = 500;
        //给积分管理，写入对应的内容
        LabBlacklist userBlack = labBlacklistMapper.selectLabBlacklistById(labBlacklist.getJoinUserId());
        if(StringUtils.isNotNull(userBlack)){
            Map<String,Object> recoveryMap = new HashMap<>();
            recoveryMap.put("joinUserId",userBlack.getJoinUserId()+"");
            recoveryMap.put("pointsType","1");
            recoveryMap.put("reason","手动恢复黑名单("+labBlacklist.getReason()+")");
            R <Object> data = remoteExamService.recoveryPoints(recoveryMap);
            if (data!=null) {
                String code = data.getCode()+"";
                if(code.equals("200")){
                    LabBlacklist labBlacklistNew = new LabBlacklist();
                    //修改黑名单状态
                    labBlacklistNew.setJoinUserId(labBlacklist.getJoinUserId());
                    labBlacklistNew.setUpdateTime(DateUtils.getNowDate());
                    labBlacklistNew.setUpdateBy(SecurityUtils.getUsername());
                    labBlacklistNew.setBlacklistStatus(0);
                    flag = labBlacklistMapper.updateLabBlacklist(labBlacklistNew);
                    //移除黑名单，需要变更详细表考试状态为已恢复。
                    LabBlackdetailVO blackdetailVO = new LabBlackdetailVO();
                    blackdetailVO.setBlackId(userBlack.getId());
                    List<LabBlackdetailVO> labBlackdetailVOList = labBlackdetailMapper.selectLabBlackdetailList(blackdetailVO);
                    int limit = 0;
                    for(LabBlackdetailVO labBlackdetailVO:labBlackdetailVOList){
                        if(limit==1){
                            break;
                        }
                        if(labBlackdetailVO.getLearnStatus().equals(0)){
                            labBlackdetailVO.setLearnStatus(2);
                        }
                        if(labBlackdetailVO.getTestStatus().equals(0)){
                            labBlackdetailVO.setTestStatus(2);
                        }
                        if(labBlackdetailVO.getPracticeStatus().equals(0)){
                            labBlackdetailVO.setPracticeStatus(2);
                        }
                        labBlackdetailVO.setUserId(null);
                        labBlackdetailVO.setOverStatus(2);
                        labBlackdetailMapper.updateLabBlackdetail(labBlackdetailVO);
                        limit++;
                    }
                    //这里调用刘吉焕的移除负面清单方法
                    iLabViolationService.resetUserRecovery(labBlacklist.getJoinUserId(),labBlacklist.getReason());
                }
            }
        }else{
            //这里调用刘吉焕的移除负面清单方法
            iLabViolationService.resetUserRecovery(labBlacklist.getJoinUserId(),labBlacklist.getReason());
        }

        return flag;
    }


    //获取黑名单惩罚时间区间
    @Override
    public LabBlackdetail getBlackTimeArea(LabBlackdetailVO blackdetailVO){
        LabBlacklist blacklist = labBlacklistMapper.selectLabBlacklistById(blackdetailVO.getJoinUserId());
        if(blacklist!=null){
            LabBlackdetail labBlackdetail = labBlackdetailMapper.selectLabBlackdetailByBlackId(blacklist.getId());
            return labBlackdetail;
        }
        return null;
    }


    /**
     * 批量删除黑名单
     *
     * @param ids 需要删除的黑名单主键
     * @return 结果
     */
    @Override
    public int deleteLabBlacklistByIds(Long[] ids) {
        return labBlacklistMapper.deleteLabBlacklistByIds(ids);
    }

    /**
     * 删除黑名单信息
     *
     * @param id 黑名单主键
     * @return 结果
     */
    @Override
    public int deleteLabBlacklistById(Long id) {
        return labBlacklistMapper.deleteLabBlacklistById(id);
    }
}
