| | |
| | | |
| | | 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 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 监管接口解析入口 |
| | |
| | | private ApiV1Service3031 apiV1Service3031; |
| | | @Resource |
| | | private ApiV1Service3032 apiV1Service3032; |
| | | |
| | | @Resource |
| | | private ApiV1Service3033 apiV1Service3033; |
| | | |
| | | @PostMapping |
| | | @ResponseBody |
| | | public ApiV1Resp<Object> gateway(@RequestBody ApiV1Req<JSONObject> req) { |
| | | public ApiV1Resp<Object> gateway(@RequestBody ApiV1Req<Object> req) { |
| | | |
| | | log.info("质押监管接口V1,收到库区网关信息={}", req); |
| | | log.debug("质押监管接口V1,收到库区网关信息={}", req.getFunctionId()); |
| | | try { |
| | | |
| | | //参数校验 |
| | |
| | | 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); |
| | |
| | | |
| | | } |
| | | |
| | | // @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]", ""); |
| | | } |
| | | |
| | | } |