package com.yonge.cooleshow.biz.dal.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yonge.cooleshow.biz.dal.dao.UserBindingTeacherDao;
import com.yonge.cooleshow.biz.dal.entity.UserBindingTeacher;
import com.yonge.cooleshow.biz.dal.service.SysConfigService;
import com.yonge.cooleshow.biz.dal.service.UserBindingTeacherService;
import com.yonge.cooleshow.common.constant.SysConfigConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: cy
 * @Date: 2022/5/26
 */
@Service("userBindingTeacherService")
public class UserBindingTeacherServiceImpl extends ServiceImpl<UserBindingTeacherDao, UserBindingTeacher> implements UserBindingTeacherService {
    private final static Logger log = LoggerFactory.getLogger(UserBindingTeacherServiceImpl.class);

    @Autowired
    private SysConfigService sysConfigService;

    @Override
    public void unbindTask() {
        String days = sysConfigService.findConfigValue(SysConfigConstant.PIANO_ROOM_UNBIND_DAYS);
        int i = Integer.parseInt(days);
        List<UserBindingTeacher> userBindingTeachers = baseMapper.queryUnbindList(i);
        if(!CollectionUtils.isEmpty(userBindingTeachers)){
            removeByIds(userBindingTeachers.stream().map(UserBindingTeacher::getId).collect(Collectors.toList()));
        }
    }
}

