LoginController.java 2.18 KB
Newer Older
谢恒's avatar
谢恒 committed
1 2 3 4 5 6 7
package com.hs.admin.controller;

import com.hs.admin.base.HsRuntimeException;
import com.hs.admin.base.Result;
import com.hs.admin.dto.UserDto;
import com.hs.admin.service.UserService;
import com.hs.admin.util.JsonUtils;
谢恒's avatar
谢恒 committed
8 9
import com.hs.admin.util.LogUtil;
import org.springframework.stereotype.Controller;
谢恒's avatar
谢恒 committed
10 11 12 13 14 15 16 17
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author xieheng
 */
谢恒's avatar
谢恒 committed
18
@Controller
谢恒's avatar
谢恒 committed
19 20 21 22 23 24 25 26 27 28 29 30 31
public class LoginController {
    @Resource
    UserService userService;
//    @Resource
//    LoginUserUtil loginUserUtil;

    /**
     * @description: 登录
     * @param: userDto
     * @return: String
     * @author: XieHeng
     * @date: 2021/5/8 3:20 下午
     */
谢恒's avatar
谢恒 committed
32
    @ResponseBody
谢恒's avatar
谢恒 committed
33 34 35 36 37 38 39 40 41
    @PostMapping(value = "/api/admin/login")
    public String login(@RequestBody UserDto userDto) {
        Result result;
        try {
            Map<String, Object> resultMap = userService.login(userDto);
            result = Result.returnSuccess(resultMap);
        } catch (HsRuntimeException e) {
            result = Result.returnHsException(e);
        } catch (Exception e) {
谢恒's avatar
谢恒 committed
42
            LogUtil.error(">>>>>\nlogin错误日志:" + e);
谢恒's avatar
谢恒 committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
            result = Result.returnError();
        }
        return JsonUtils.beanToJson(result);
    }

    /**
     * @description: 用户列表
     * @param: pageNum
     * @param: pageSize
     * @return: String
     * @author: XieHeng
     * @date: 2021/5/8 5:37 下午
     */
/*    @GetMapping(value = "/api/admin/userList")
    public String userList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
        Result result;
        try {
            loginUserUtil.getLoginUser();
            List<Map> userList = userService.getList(pageNum, pageSize);
            result = Result.returnSuccess(userList);
        } catch (HsRuntimeException e) {
            result = Result.returnHsException(e);
        } catch (Exception e) {
            e.printStackTrace();
            result = Result.returnError();
        }
        return JsonUtil.beanToJson(result);
    }*/
谢恒's avatar
谢恒 committed
71 72 73 74
    @GetMapping(value = "/api/admin/index")
    public String index(){
        return "index";
    }
谢恒's avatar
谢恒 committed
75
}