package com.JN.controller;

import com.JN.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PageRedirectController
 * @Description TODO
 * @Author JN
 * @Date 2024/1/12 14:44
 * @Version 1.0
 */
@Controller
@Slf4j
public class PageRedirectController {

    @Autowired
    EmployeeService employeeService;
    /**
     * @title redirectBiz
     * @description 后台接收带工号的URL请求跳转界面
     * @author JN
     * @param: id
     * @param: model
     * @updateTime 2024/1/15 8:23
     * @return: java.lang.String
     */
    @RequestMapping(value = "/Biz", method = {RequestMethod.GET, RequestMethod.POST})
    public String redirectBiz(@RequestParam("id") String id, Model model) {
        log.info("登入工号为： {}", id);
        // 将工号添加到Model中
        String name = employeeService.queryNameById(id);
        model.addAttribute("employeeId", id);
        model.addAttribute("employeeName", name);

        if(name == null || name.equals("")) {
            return "bizquery/error";
        }

        return "bizquery/index";
    }

}
