From dea35289149c88a91677e5d27ea42aac8c902d07 Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期五, 22 十一月 2024 21:26:57 +0800
Subject: [PATCH] feign xml 实现
---
jh-server/src/main/resources/application-local.yaml | 3 +
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/RemoteDataService.java | 8 +++-
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/MyOpenFeignConfig.java | 6 +++
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java | 7 ++-
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/FeeConfirmFeignService.java | 20 ++++++++++
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/FeignXmlConfiguration.java | 55 +++++++++++++++++++++++++++
6 files changed, 95 insertions(+), 4 deletions(-)
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/FeignXmlConfiguration.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/FeignXmlConfiguration.java
new file mode 100644
index 0000000..0a5e9d5
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/FeignXmlConfiguration.java
@@ -0,0 +1,55 @@
+package cn.lihu.jh.module.ecg.config;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import feign.RequestTemplate;
+import feign.Response;
+import feign.codec.DecodeException;
+import feign.codec.Decoder;
+import feign.codec.EncodeException;
+import feign.codec.Encoder;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+
+@Slf4j
+public class FeignXmlConfiguration {
+
+ @Bean
+ public Encoder feignEncoder() {
+ return new Encoder.Default() {
+ @Override
+ public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
+ try {
+ XmlMapper xmlMapper = new XmlMapper();
+ String xml = xmlMapper.writeValueAsString(object);
+ template.body(xml.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
+ } catch (JsonProcessingException e) {
+ throw new EncodeException(e.getMessage(), e);
+ }
+ }
+ };
+ }
+
+ @Bean
+ public Decoder feignDecoder() {
+ return new Decoder.Default() {
+ @Override
+ public Object decode(Response response, Type type) throws IOException {
+ try {
+ XmlMapper xmlMapper = new XmlMapper();
+ return xmlMapper.readValue(response.body().asInputStream(), xmlMapper.constructType(type));
+ } catch (IllegalArgumentException e) {
+ throw new DecodeException(response.status(), e.getMessage(), response.request());
+ }
+ }
+ };
+ }
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/MyOpenFeignConfig.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/MyOpenFeignConfig.java
index 8c85ccc..ccc52f8 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/MyOpenFeignConfig.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/MyOpenFeignConfig.java
@@ -1,5 +1,6 @@
package cn.lihu.jh.module.ecg.config;
+import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -18,4 +19,9 @@
ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(converter);
return new SpringDecoder(objectFactory);
}
+
+ @Bean
+ Logger.Level feignLoggerLevel() {
+ return Logger.Level.FULL; // 璁剧疆Feign鏃ュ織绾у埆涓篎ULL
+ }
}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/FeeConfirmFeignService.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/FeeConfirmFeignService.java
new file mode 100644
index 0000000..ed0a877
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/FeeConfirmFeignService.java
@@ -0,0 +1,20 @@
+package cn.lihu.jh.module.ecg.feign;
+
+import cn.lihu.jh.module.ecg.config.FeignXmlConfiguration;
+import cn.lihu.jh.module.ecg.feign.dto.AppointmentExternal;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@FeignClient(name = "remote-fee-confirm-service", url = "${openfeign.server}",
+ configuration = FeignXmlConfiguration.class)
+public interface FeeConfirmFeignService {
+
+ @PostMapping(value="/hai/HttpEntry/", produces = MediaType.APPLICATION_XML_VALUE/*, consumes = MediaType.APPLICATION_JSON_VALUE*/)
+ public HisFeeConfirmRespResult httpFeeApi( @RequestParam("service") String service,
+ @RequestParam("urid") String urid,
+ @RequestParam("pwd") String pwd,
+ @RequestBody HisFeeConfirmReqBody bodyVo);
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/RemoteDataService.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/RemoteDataService.java
index 17a0ca1..ee26b50 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/RemoteDataService.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/RemoteDataService.java
@@ -13,9 +13,13 @@
@RequestParam("pwd") String pwd,
@RequestBody RestApiReqBodyVo bodyVo);
- @PostMapping(value="/hai/HttpEntry/", produces = MediaType.APPLICATION_XML_VALUE/*, consumes = MediaType.APPLICATION_JSON_VALUE*/)
- public HisFeeConfirmRespResult httpFeeApi( @RequestParam("service") String service,
+/*
+ @PostMapping(value="/hai/HttpEntry/", produces = MediaType.APPLICATION_XML_VALUE*/
+/*, consumes = MediaType.APPLICATION_JSON_VALUE*//*
+)
+ public String httpFeeApi( @RequestParam("service") String service,
@RequestParam("urid") String urid,
@RequestParam("pwd") String pwd,
@RequestBody HisFeeConfirmReqBody bodyVo);
+*/
}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java
index c7bacba..16fb61b 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java
@@ -21,6 +21,7 @@
import cn.lihu.jh.module.ecg.service.queue.QueueServiceTxFunctions;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
@@ -53,13 +54,14 @@
*/
@Service
@Validated
+@Slf4j
public class DevRentServiceImpl implements DevRentService {
@Resource
QueueServiceTxFunctions queueServiceTxFunctions;
@Resource
- private RemoteDataService remoteDataService;
+ private FeeConfirmFeignService feeConfirmFeignService;
@Resource
private DevRentMapper devRentMapper;
@@ -749,7 +751,8 @@
exmRequest.setPatientType( getPatientType(patDetails.getSource()) ); //
exmRequest.setItem(item);
hisFeeConfirmReqBody.setExmRequest(exmRequest);
- HisFeeConfirmRespResult result = remoteDataService.httpFeeApi("UpdateExmRequestStatus", "ECG", "ECG", hisFeeConfirmReqBody);
+ HisFeeConfirmRespResult result = feeConfirmFeignService.httpFeeApi("UpdateExmRequestStatus", "ECG", "ECG", hisFeeConfirmReqBody);
+ log.info( result.getMsgHeader().getStatus() );
Integer returnValue = result.getMsgHeader().getStatus().equals("true") ? 0 : 1;
if (0 == returnValue) {
devRentMapper.setPaid(rentId, isFeeConfirmOrCancel ? 1 : 0);
diff --git a/jh-server/src/main/resources/application-local.yaml b/jh-server/src/main/resources/application-local.yaml
index 88359e7..e2deb52 100644
--- a/jh-server/src/main/resources/application-local.yaml
+++ b/jh-server/src/main/resources/application-local.yaml
@@ -182,6 +182,9 @@
cn.lihu.jh.module.ai.dal.mysql: debug
cn.lihu.jh.module.ecg.dal.mysql: debug
org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 鑺嬭壙锛氬厛绂佺敤锛孲pring Boot 3.X 瀛樺湪閮ㄥ垎閿欒鐨� WARN 鎻愮ず
+ org.springframework.cloud.openfeign: debug
+ feign: debug
+ cn.lihu.jh.module.ecg.feign: debug
debug: false
--
Gitblit v1.9.3