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;
|
@Resource
|
private ApiV1Service3033 apiV1Service3033;
|
|
@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);
|
case ApiV1Constant.API_FUNCTION_3033:
|
return apiV1Service3033.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]", "");
|
}
|
|
}
|