package com.ruoyi.test.business;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.test.RefreshArea;
import com.ruoyi.xq.domain.User;
import com.ruoyi.xq.job.JobManager;
import com.ruoyi.xq.service.UserService;
import com.ruoyi.xq.util.AgeUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
@Slf4j
public class RefreshTest {
    @Autowired
    private RefreshArea refreshArea;
    @Autowired
    private JobManager jobManager;
    @Autowired
    private UserService userService;

    @Test
    public void refresh(){
        refreshArea.refreshPinyin();
    }

    @Test
    public void updateAge(){
        jobManager.updateAge();
    }

    @Test
    public void refreshUserAreaCode(){
        jobManager.refreshUserAreaCode();
    }


    @Test
    public void checkBaseStatus(){
        int current = 0;
        while (true){
            current++;
            IPage<User> page = new Page<>();
            page.setCurrent(current);
            page.setSize(100);
            IPage<User> userPage = userService.page(page);
            List<User> records = userPage.getRecords();
            if(records.isEmpty()){
                break;
            }
            for (User record : records) {
                userService.checkFinishStatus(record.getId());
            }
        }
    }
}
