package com.muyu.system.saas.controller;

import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.security.annotation.InnerAuth;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysUser;
import com.muyu.system.saas.service.SysUserService;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: 胡杨
 * @Name: SysUser
 * @Description:
 * @CreatedDate: 2024/9/23 下午8:55
 * @FilePath: com.muyu.system.saas.controller
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class SysUserController {
    @Resource
    private SysUserService userService;

    @InnerAuth
    @GetMapping("/info")
    public Result<SysUser> info (
            @RequestParam("firmCode") String firmCode,
            @RequestParam("userName") String userName) {
        DynamicDataSourceHolder.setDynamicDataSourceKey(firmCode);
        SysUser sysUser = userService.selectUserByUserName(userName);
        if (StringUtils.isNull(sysUser)) {
            return Result.error("用户名或密码错误");
        }
        return Result.success(sysUser);
    }
}
