sgj
2026-02-03 9e64b2df66a7ab69b9daf258999d88844cccecce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package com.fzzy.igds.api.v1;
 
import com.fzzy.igds.api.v1.data.ApiV1Req;
import com.fzzy.igds.api.v1.data.ApiV1Resp;
import com.fzzy.igds.api.v1.data.Param3030;
import com.fzzy.igds.api.v1.service.*;
import com.fzzy.igds.api.v1.util.ApiV1Constant;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.domain.GatewaySer;
import com.fzzy.igds.service.GatewaySerService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
 
/**
 * @Description 监管接口解析入口
 * @Author CZT
 * @Date 2026/1/7 10:25
 */
@Slf4j
@Controller
@RequestMapping("api/igdss/v1")
public class ApiV1Controller {
 
    @Resource
    private GatewaySerService gatewaySerService;
    @Resource
    private ApiV1Service3010 apiV1Service3010;
    @Resource
    private ApiV1Service3020 apiV1Service3020;
    @Resource
    private ApiV1Service3021 apiV1Service3021;
    @Resource
    private ApiV1Service3022 apiV1Service3022;
    @Resource
    private ApiV1Service3030 apiV1Service3030;
    @Resource
    private ApiV1Service3031 apiV1Service3031;
    @Resource
    private ApiV1Service3032 apiV1Service3032;
 
    @PostMapping
    @ResponseBody
    public ApiV1Resp<Object> gateway(@RequestBody ApiV1Req<Object> req) {
 
        log.debug("质押监管接口V1,收到库区网关信息={}", req.getFunctionId());
        try {
 
            //参数校验
            if (req == null) {
                return ApiV1Resp.error("参数有误!", req);
            }
 
            //校验接口编码和网关SN
            if (StringUtils.isEmpty(req.getFunctionId()) || StringUtils.isEmpty(req.getSn())) {
                return ApiV1Resp.error("参数有误!", req);
            }
 
            //校验网关是否存在
            GatewaySer gatewaySer = gatewaySerService.getCacheSerById(null, req.getSn());
            if (null == gatewaySer) {
                return ApiV1Resp.error("当前网关<SN=" + req.getSn() + ">暂未添加,请核查!", req);
            }
 
            //异步更新网关状态
            gatewaySerService.updateStatus(gatewaySer, Constant.YN_Y, ApiV1Constant.API_FUNCTION_3010.equals(req.getFunctionId()));
 
            //解析
            String functionId = req.getFunctionId();
            switch (functionId) {
                case ApiV1Constant.API_FUNCTION_3010:
                    return apiV1Service3010.analysis(req, gatewaySer);
                case ApiV1Constant.API_FUNCTION_3020:
                    return apiV1Service3020.analysis(req, gatewaySer);
                case ApiV1Constant.API_FUNCTION_3021:
                    return apiV1Service3021.analysis(req, gatewaySer);
                case ApiV1Constant.API_FUNCTION_3022:
                    return apiV1Service3022.analysis(req, gatewaySer);
                case ApiV1Constant.API_FUNCTION_3030:
                    return apiV1Service3030.analysis(req, gatewaySer);
                case ApiV1Constant.API_FUNCTION_3031:
                    return apiV1Service3031.analysis(req, gatewaySer);
                case ApiV1Constant.API_FUNCTION_3032:
                    return apiV1Service3032.analysis(req, gatewaySer);
            }
 
            return ApiV1Resp.error("接口编码<" + functionId + ">不存在,请核查!", req);
 
        } catch (Exception e) {
 
            log.info("质押监管接口V1,接口解析异常={}", e.toString());
 
            return ApiV1Resp.error("解析异常!", req);
        }
 
    }
 
    //    @PostMapping
//    @ResponseBody
//    public ApiV1Resp<Object> receiveRawRequest(HttpServletRequest request) throws IOException {
//        // 读取原始请求体
//        String rawJson = StreamUtils.copyToString(request.getInputStream(), StandardCharsets.UTF_8);
//        System.out.println("原始请求JSON:" + rawJson);
////        System.out.println("第92列字符:" + (rawJson.length() >= 92 ? rawJson.charAt(91) : "长度不足"));
//        rawJson = cleanInvalidUtf8(rawJson);
//        ApiV1Req<Object> req = JSONObject.parseObject(rawJson, ApiV1Req.class);
//
//
//        log.debug("质押监管接口V1,收到库区网关信息={}", req.getFunctionId());
//        try {
//
//            //参数校验
//            if (req == null) {
//                return ApiV1Resp.error("参数有误!", req);
//            }
//
//            //校验接口编码和网关SN
//            if (StringUtils.isEmpty(req.getFunctionId()) || StringUtils.isEmpty(req.getSn())) {
//                return ApiV1Resp.error("参数有误!", req);
//            }
//
//            //校验网关是否存在
//            GatewaySer gatewaySer = gatewaySerService.getCacheSerById(null, req.getSn());
//            if (null == gatewaySer) {
//                return ApiV1Resp.error("当前网关<SN=" + req.getSn() + ">暂未添加,请核查!", req);
//            }
//
//            //异步更新网关状态
//            gatewaySerService.updateStatus(gatewaySer, Constant.YN_Y, ApiV1Constant.API_FUNCTION_3010.equals(req.getFunctionId()));
//
//            //解析
//            String functionId = req.getFunctionId();
//            switch (functionId) {
//                case ApiV1Constant.API_FUNCTION_3010:
//                    return apiV1Service3010.analysis(req, gatewaySer);
//                case ApiV1Constant.API_FUNCTION_3020:
//                    return apiV1Service3020.analysis(req, gatewaySer);
//                case ApiV1Constant.API_FUNCTION_3021:
//                    return apiV1Service3021.analysis(req, gatewaySer);
//                case ApiV1Constant.API_FUNCTION_3022:
//                    return apiV1Service3022.analysis(req, gatewaySer);
//                case ApiV1Constant.API_FUNCTION_3030:
//                    return apiV1Service3030.analysis(req, gatewaySer);
//                case ApiV1Constant.API_FUNCTION_3031:
//                    return apiV1Service3031.analysis(req, gatewaySer);
//                case ApiV1Constant.API_FUNCTION_3032:
//                    return apiV1Service3032.analysis(req, gatewaySer);
//            }
//
//            return ApiV1Resp.error("接口编码<" + functionId + ">不存在,请核查!", req);
//
//        } catch (Exception e) {
//
//            log.info("质押监管接口V1,接口解析异常={}", e.toString());
//
//            return ApiV1Resp.error("解析异常!", req);
//        }
////        // 后续逻辑...
////        return "success";
//    }
 
    // 清理无效UTF-8字符和控制字符
    public static String cleanInvalidUtf8(String json) {
        if (json == null) return null;
        // 移除无效UTF-8字节和控制字符(除了换行、回车、制表符)
        return json.replaceAll("[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F-\\x9F\\xC1]", "");
    }
 
}