package com.ensign.crm.module.crm.evnet.listener;

import com.ensign.crm.module.crm.exception.AllKingdeeException;
import com.ensign.crm.module.crm.job.service.TaskHandler;
import com.ensign.crm.module.system.event.UserRegisterEvent;
import com.ensign.crm.module.system.service.permission.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;

/**
 * @Description: TODO
 * @Date: 2024/10/15 16:14
 * @Created: by ZZSLL
 */


@Component
@Slf4j
public class UserRegisterEventLister {

    @Autowired
    private TaskHandler taskHandler;

    @Autowired
    private PermissionService permissionService;

    @EventListener
    public void onRegister(UserRegisterEvent event) throws AllKingdeeException, IOException, URISyntaxException {
        log.info("[UserRegisterEventLister] onRegister");
        taskHandler.syncUser(event.getAdminUserDO(), new ArrayList<>());
        permissionService.assignPermissions(event.getAdminUserDO());
    }
}
