//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.luozhihui.project.controller;

import com.luozhihui.project.common.LoginResponse;
import com.luozhihui.project.entity.Admin;
import com.luozhihui.project.mapper.AdminLoginMapper;
import com.luozhihui.project.util.JwtUtil;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/api"})
@CrossOrigin
public class AdminLoginController {
    @Resource
    AdminLoginMapper adminLoginMapper;

    public AdminLoginController() {
    }

    @PostMapping({"/admin_login"})
    public LoginResponse login(@RequestParam("AdminUser") String AdminUser, @RequestParam("AdminPassWord") String AdminPassWord) {
        List<Admin> userList = this.adminLoginMapper.findByPhone(AdminUser);
        System.out.println(userList);
        if (userList.isEmpty()) {
            return new LoginResponse((Object)null, (Object)null, 500, "用户不存在");
        } else {
            Admin admin = (Admin)userList.get(0);
            if (admin.getAdminPassWord().equals(AdminPassWord)) {
                JwtUtil jwtUtil = new JwtUtil();
                String token = JwtUtil.createToken(((Admin)userList.get(0)).getAdminUser());
                return new LoginResponse(token, (Object)null, 200, "登录成功");
            } else {
                return new LoginResponse((Object)null, (Object)null, 500, "密码错误");
            }
        }
    }
}
