package com.jwipc.sys.controller.pc;

import com.jwipc.sys.dto.FactoryDTO;
import com.jwipc.sys.logic.FactoryLogic;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * @author shenyang.ou
 * @date 2024/1/29 14:53
 * @desc 工厂
 */
@Controller
@RequestMapping(MODULE_ROOT + "/factory")
@RequiredArgsConstructor
public class FactoryPageController {
    private final FactoryLogic factoryLogic;

    @GetMapping("/index")
    public String index() {
        return MODULE_ROOT + "/factory/list";
    }

    @GetMapping("/detail")
    public String detail(Model model,Long id) {
        FactoryDTO factory;
        if (id != null) {
            factory = factoryLogic.getById(id);
        } else {
            factory = new FactoryDTO();
        }
        model.addAttribute("factory", factory);
        return MODULE_ROOT + "/factory/detail";
    }

    /**
     * 分配工厂
     *
     * @return
     */
    @GetMapping("userFactoryAdd")
    public String userFactoryAdd(Long userId, Model model) {
        model.addAttribute("userId", userId);
        return MODULE_ROOT + "/factory/user_factory_add";

    }
}
