package com.mcwl.communityCenter.task;


import com.mcwl.communityCenter.domain.CommunityUser;
import com.mcwl.communityCenter.service.CommunityUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("communityUserTask")
@RequiredArgsConstructor
public class CommunityUserTask {

    private final CommunityUserService communityUserService;



    /**
     * 拉出拉黑的社区用户 每隔30分钟执行  0 0/30 * * * ? *
     */
    public void pullOutBlackUser() {

        List<CommunityUser> communityUserList = communityUserService.getAllCommunityUser();
        for (CommunityUser communityUser : communityUserList) {
            String isBlank = communityUser.getIsBlack();
            if ("1".equals(isBlank) && communityUser.getBlackEndTime().getTime() < System.currentTimeMillis()) {
                communityUser.setIsBlack("0");
                communityUser.setBlackEndTime(null);
                communityUser.setBlackReason(null);
                communityUserService.updateBlankCommunityUser(communityUser);
            }
        }

    }



}
