package com.jwipc.sys.controller.pc;

import cn.hutool.core.util.ObjectUtil;
import com.jwipc.sys.dto.LogThirdPartyCallDTO;
import com.jwipc.sys.dto.LogThirdPartyInterfaceDTO;
import com.jwipc.sys.dto.SapLogInfoDTO;
import com.jwipc.sys.logic.ThirdLogLogic;
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;

/**
 * <p>
 * 系统第三方接口日志 前端控制器
 * </p>
 *
 * @author shenyang.ou
 * @since 2024-01-29
 */
@Controller
@RequestMapping(MODULE_ROOT + "/thirdLog")
@RequiredArgsConstructor
public class ThirdLogPageController {
    private final ThirdLogLogic thirdLogLogic;

    /**
     * 日志
     * @param type 类型；0-接收方；1-调用方日志
     * @return
     */
    @GetMapping("/index")
    public String index(Model model,Integer type) {
        model.addAttribute("type",type);
        return MODULE_ROOT + "/log/third/list";
    }

    @GetMapping("/look")
    public String look(Model model, String id,Integer type) {
        type = type==null?0:type;
        if (type==0){
            LogThirdPartyInterfaceDTO dto = thirdLogLogic.getById(id);
            if (ObjectUtil.isNull(dto)){
                model.addAttribute("log", thirdLogLogic.getCallById(id));
            }else {
                model.addAttribute("log", dto);
            }

        }else {
            LogThirdPartyCallDTO dto = thirdLogLogic.getCallById(id);
            if (ObjectUtil.isNull(dto)){
                model.addAttribute("log", thirdLogLogic.getById(id));
            }else {
                model.addAttribute("log", dto);
            }
        }
        model.addAttribute("type",type);
        return MODULE_ROOT + "/log/third/look";
    }
}
