package com.jwipc.tender.controller.pc;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil;
import com.jwipc.log.annotation.AuditLogInter;
import com.jwipc.tender.constant.ModuleConst;
import com.jwipc.util.EncryptUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 org.springframework.web.bind.annotation.RequestParam;

import java.util.Objects;

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

/**
 * <p>定标管理相关页面</p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Controller
@RequiredArgsConstructor
@Slf4j
@RequestMapping(ModuleConst.MODULE_ROOT + "/benchmarks/page")
public class BenchmarksPageController {

    /**
     * 定标管理 列表页面
     *
     * @return
     */
    @GetMapping("index")
    public String index(Model model, Integer type) {
        model.addAttribute("type", Objects.nonNull(type) ? type : "");
        return MODULE_ROOT + "/benchmarks/index";
    }

    /**
     * 投标单详情页面
     *
     * @param type 0:查看;1:定标
     * @param id   招标单id
     * @return
     * @see com.jwipc.tender.constant.TenderOptType
     */
    @GetMapping("detail")
    @AuditLogInter(module = "招投标管理",value = "定标管理-查看定标")
    public String detail(@RequestParam(required = false, defaultValue = "0") String id,
                         @RequestParam(required = false, defaultValue = "0") Integer type,
                         Model model)
    {
        if (!StrUtil.isNumeric(id)) {
            id = EncryptUtils.decrypt(id);
            //需要模拟登录
            if(!StpUtil.isLogin()){
                StpUtil.login(-99999,30);
            }
        }
        model.addAttribute("id", id);
        model.addAttribute("type", type);
        return MODULE_ROOT + "/benchmarks/detail";
    }
    @GetMapping("confirmUser")
    public String confirmUser(Long tenderId, Model model) {
        model.addAttribute("tenderId", tenderId);
        return MODULE_ROOT + "/benchmarks/confirm_user";
    }
}
