package com.njzscloud.dispose.sys.auth.controller;

import cn.hutool.core.lang.Assert;
import com.njzscloud.common.core.ex.Exceptions;
import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.security.support.UserDetail;
import com.njzscloud.common.security.util.SecurityUtil;
import com.njzscloud.dispose.sys.auth.service.AuthService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录
 */
@Slf4j
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {
    private final AuthService authService;

    /**
     * 获取当前登录人信息
     */
    @GetMapping("/my")
    public R<UserDetail> my() {
        UserDetail userDetail = SecurityUtil.loginUser();
        Long userId = userDetail.getUserId();
        Integer client = userDetail.getClient();

        Assert.notNull(client, () -> Exceptions.exception("客户端信息错误"));

        return R.success(authService.my(userId, client));
    }
}
