package com.goldenwater.slgc.controller.proxy;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "28. 通用ASMX代理")
@RestController
@RequestMapping("/slgc/asmx")
public class AsmxProxyController extends BaseController {

    private static final String YJZH_BASE = "http://10.8.4.171:816";
    private static final String NEWGQ_BASE = "http://10.8.40.222/WebService";

    @Operation(summary = "28.01 通用ASMX代理转发")
    @GetMapping("/{type}/{fun}")
    public AjaxResult proxy(@PathVariable String type, @PathVariable String fun, HttpServletRequest request) {
        String query = request.getQueryString();
        String base = "NewGQ".equals(type) ? NEWGQ_BASE : YJZH_BASE;
        return success(ProxyHelper.fetchSoapXmlToJson(base + "/" + type + ".asmx/" + fun + (query != null ? "?" + query : "")));
    }
}
