package com.jwipc.spe.controller;

import com.jwipc.security.LoginUtil;
import com.jwipc.spe.dto.QmAuditManageDTO;
import com.jwipc.spe.logic.QmAuditManageLogic;
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.spe.constant.ModuleConst.MODULE_ROOT;

/**
 * @author Al
 * @create 2024-03-19 14:55
 * 稽核整改
 */
@Controller
@RequestMapping(MODULE_ROOT + "/qmAuditManage")
@RequiredArgsConstructor
public class QmAuditManagePageController {
    private final QmAuditManageLogic qmAuditManageLogic;
    //主页面
    @GetMapping("/index")
    public String index(Model model) {
        // isSup -> 0:非供应商 1:供应商
        model.addAttribute("isSup", LoginUtil.isSupplier());
        if(LoginUtil.isSupplier()){
            return MODULE_ROOT + "/qmAuditManage/suplist";
        }else{
            return MODULE_ROOT + "/qmAuditManage/list";
        }

    }
    //新增编辑详情页
    @GetMapping("/detail")
    public String detail(Model model, Long id,Integer flag) {
        QmAuditManageDTO qmAuditManageDTO;
        qmAuditManageDTO = qmAuditManageLogic.getById(id);
        // isSup -> 0:非供应商 1:供应商
        model.addAttribute("isSup", LoginUtil.isSupplier());
        model.addAttribute("qmAuditManageDTO", qmAuditManageDTO);
        model.addAttribute("flag", flag);
        if(LoginUtil.isSupplier()){
            return MODULE_ROOT + "/qmAuditManage/supdetail";
        }else{
            return MODULE_ROOT + "/qmAuditManage/detail";
        }

    }
    //查看页面
    @GetMapping("/look")
    public String look(Model model, Long id) {
        QmAuditManageDTO qmAuditManageDTO;
        qmAuditManageDTO = qmAuditManageLogic.getById(id);
        model.addAttribute("qmAuditManageDTO", qmAuditManageDTO);
        if(LoginUtil.isSupplier()){
            return MODULE_ROOT + "/qmAuditManage/suplook";
        }else{
            return MODULE_ROOT + "/qmAuditManage/look";
        }

    }
    //审核页面
    @GetMapping("/examine")
    public String examine(Model model, Long id) {
        QmAuditManageDTO qmAuditManageDTO;
        qmAuditManageDTO = qmAuditManageLogic.getById(id);
        model.addAttribute("qmAuditManageDTO", qmAuditManageDTO);
        return MODULE_ROOT + "/qmAuditManage/examine";
    }
    }
