package cn.pluss.platform.job;

import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.mapper.UserAppMapper;
import cn.pluss.platform.userApp.UserAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时检查用户实名认证状态
 * @author admin
 *
 * @Description
 */
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = "scheduling", name = "enabled", havingValue = "true")
public class CheckUserCertStatusJob {

    @Autowired
    private UserAppService uaService;

    @Resource
    private UserAppMapper userAppMapper;

    /**
     * 查询出1小时内没有完成实名认证的用户，并驳回
     */
    @Scheduled(fixedDelay = 5  * 1000)
    public void refuseUserCert() {

        List<UserApp> uaList = userAppMapper.selectUserInCert();
        for (UserApp ua : uaList) {
            uaService.userCert(ua.getUserId() + "", 2, "实名认证超时，已自动驳回");
        }
    }
}