package com.weaver.seconddev.interfaces.workflow.controller;


import com.alibaba.fastjson.JSONObject;
import com.weaver.common.authority.annotation.WeaPermission;
import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.common.security.json.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: XinfengYin
 * @CreateTime: 2025-02-17
 * @Description: IP地址赋值
 */



@Slf4j
@RestController
@RequestMapping({"/papi/secondev/workflow/controller" })
public class HTGD_IT13_GETIP_CONTROLLER {
    @GetMapping("/getip")
    @ResponseBody
    @WeaPermission(publicPermission = true)
    public WeaResult<String> run( HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("application/x-www-form-urlencoded; charset=utf-8");
        log.error("HTGD_IT13_GETIP_CONTROLLER"+ JSON.parseObjectToString(request));
        String remoteAddr = request.getRemoteAddr();
        Map<String,Object> data = new HashMap<>();
         data.put("ip",remoteAddr);
        return WeaResult.success(JSONObject.toJSONString(data));
    }


    public static String null2String(String s){
        return s == null ? "" : s;
    }

    public static String null2String(Object o){
        return o == null ? "" : o.toString();
    }

    public static String null2String(String s1,String s2){
        return s1 == null ? (s2 == null ? "" : s2) : s1;
    }
}
