eight
2024-11-22 dea35289149c88a91677e5d27ea42aac8c902d07
feign xml 实现
已添加2个文件
已修改4个文件
99 ■■■■■ 文件已修改
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/FeignXmlConfiguration.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/MyOpenFeignConfig.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/FeeConfirmFeignService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/feign/RemoteDataService.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/devrent/DevRentServiceImpl.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-server/src/main/resources/application-local.yaml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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());
                }
            }
        };
    }
}
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日志级别为FULL
    }
}
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);
}
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);
*/
}
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);
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 èŠ‹è‰¿ï¼šå…ˆç¦ç”¨ï¼ŒSpring Boot 3.X å­˜åœ¨éƒ¨åˆ†é”™è¯¯çš„ WARN æç¤º
    org.springframework.cloud.openfeign: debug
    feign: debug
    cn.lihu.jh.module.ecg.feign: debug
debug: false