package org.dromara.system.service;


import lombok.RequiredArgsConstructor;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.system.domain.bo.SysDeptBo;
import org.dromara.system.domain.vo.SysDeptVo;
import org.dromara.system.mapper.SysDeptMapper;
import org.dromara.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
@Service
@Component
public class Task {

    private final SysUserMapper userMapper;

    private final SysDeptMapper sysDeptMapper;

    private final ISysUserService sysUserService;



    /***
     * 生成班级下课初始信息
     * */
    @Async
    //@Scheduled(cron = "0 0/2 * * * ? ")
    @Scheduled(cron = "0 1 0 * * ? ")
    public void afterClass() {

        //获取所有部门
        List<SysDeptVo> sysDeptList = sysDeptMapper.selectDeptListMapper(new SysDeptBo());

        //学校部门
        List<SysDeptVo> fSysDeptList = new ArrayList<>();
        //班级部门
        List<SysDeptVo> pSysDeptList = new ArrayList<>();

        for (SysDeptVo sysDept : sysDeptList) {
            if (sysDept.getParentId() == 0) {
                fSysDeptList.add(sysDept);
            } else {
                pSysDeptList.add(sysDept);
            }
        }

        for (SysDeptVo sysDept : fSysDeptList) {
            for (SysDeptVo dept : pSysDeptList) {
                if (sysDept.getDeptId().equals(dept.getParentId())) {
                    String key = sysDept.getDeptId() + ":" + dept.getDeptId();
                    String value = dept.getDeptName() + ":time";
                    RedisUtils.setCacheObject(key, value);
                }
            }
        }
    }
    /***
     * 生成班级下课初始信息
     * */
    /*@Async
    //@Scheduled(cron = "0 0/2 * * * ? ")
    @Scheduled(cron = "0 1 0 * * ? ")
    public void afterClass() throws Exception {

    }*/

}
