package com.cpop.oam.framework.config;

import com.cpop.core.base.enums.InitRoleEnum;
import com.cpop.core.utils.SpringUtils;
import com.cpop.oam.business.entity.Task;
import com.cpop.oam.business.service.TaskService;
import com.cpop.system.business.entity.Role;
import com.cpop.system.business.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

import java.time.Duration;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static com.cpop.oam.business.entity.table.TaskTableDef.TASK;
import static org.springframework.integration.config.xml.IntegrationNamespaceUtils.ROLE;

/**
 * 初始化配置
 * @author DB
 * @since 2023-11-30 15:33:30
 * @version 1.0.0
 */
@Component
@Slf4j
public class InitConfig {

    /**
     * 初始化
     */
    @PostConstruct
    public void init() {
        log.info("===========================项目启动角色初始化===========================");
        // 检查角色初始化
        RoleService roleService = SpringUtils.getBean(RoleService.class);
        for (InitRoleEnum value : InitRoleEnum.values()) {
            Role role = roleService.queryChain().where("id = ?", value.getId()).one();
            if (role == null) {
                Role newRole = new Role();
                newRole.setId(value.getId())
                    .setRoleName(value.getRoleName())
                    .setRoleValue(value.getRoleValue())
                    .setOrderNo(value.getOrderNo())
                    .setUserType(value.getUserType());
                roleService.save(newRole);
            }
        }
    }

}
