package com.aiotagro.cattletrade.business.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import com.aiotagro.cattletrade.business.dto.LoginDto;
import com.aiotagro.cattletrade.business.service.LoginService;
import com.aiotagro.common.core.web.domain.AjaxResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 登录
 */
@RestController
public class LoginControl {

    @Resource
    private LoginService loginService;

    /**
     * 获取登录验证码
     */
    @SaIgnore
    @GetMapping("/sendLoginSmsCode")
    public AjaxResult sendLoginSmsCode(@RequestParam String mobile) {
        return loginService.sendLoginSmsCode(mobile);
    }

    /**
     * 登录
     */
    @SaIgnore
    @PostMapping("/login")
    public AjaxResult login(@Validated @RequestBody LoginDto dto) {
        return loginService.login(dto);
    }

    /**
     * 根据登录用户获取菜单列表
     **/
    @GetMapping("/getUserMenus")
    public AjaxResult getUserMenus() {
        return loginService.getUserMenus();
    }


    /**
     * 退出登录
     */
    @GetMapping("/logout")
    public AjaxResult logout() {
        StpUtil.logout();
        return AjaxResult.success("退出成功");
    }

    /**
     * 小程序我的
     **/
    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo() {
        return loginService.getUserInfo();
    }
}
