异常备用
parent
986be2f120
commit
b5786d1024
@ -0,0 +1,8 @@
|
||||
[
|
||||
{
|
||||
"method": "WS_RECORD_SUBMIT",
|
||||
"urls": ["http://127.0.0.1:9312/message/receive1/wsRecordSubmit/do"],
|
||||
"errorResult": "<Response><RetInfo><RetCode>1</RetCode><RetCon>系统错误!</RetCon></RetInfo></Response>",
|
||||
"messageDataType": 1
|
||||
}
|
||||
]
|
@ -0,0 +1,47 @@
|
||||
package com.docus.server.message.config;
|
||||
|
||||
import com.docus.core.util.Func;
|
||||
import com.docus.server.message.enums.DataFormatEnum;
|
||||
import com.docus.server.message.util.TableJsonRead;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
*/
|
||||
public class WsMessageForwardConfig {
|
||||
private final static String CONFIG_FILE_PATH = "data-config";
|
||||
private final static String CONFIG_FILE_NAME = "ws-message-forward-config.json";
|
||||
|
||||
public static WsMessageForward wsMessageForward(String method) {
|
||||
Objects.requireNonNull(method);
|
||||
TableJsonRead jsonReader = new TableJsonRead();
|
||||
String wsMessageForwardConfigJson = jsonReader.ReadContent(CONFIG_FILE_PATH, CONFIG_FILE_NAME);
|
||||
if (wsMessageForwardConfigJson == null) {
|
||||
return null;
|
||||
}
|
||||
List<WsMessageForward> wsMessageForwardList = Func.parseJsonArray(wsMessageForwardConfigJson, WsMessageForward.class);
|
||||
if (Func.isEmpty(wsMessageForwardList)) {
|
||||
return null;
|
||||
}
|
||||
for (WsMessageForward wsMessageForward : wsMessageForwardList) {
|
||||
if (method.equals(wsMessageForward.getMethod())) {
|
||||
return wsMessageForward;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class WsMessageForward {
|
||||
private String method;
|
||||
private List<String> urls;
|
||||
private String errorResult;
|
||||
/**
|
||||
* @see DataFormatEnum#getValue()
|
||||
*/
|
||||
private Integer messageDataType;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.docus.server.message.consts;
|
||||
|
||||
/**
|
||||
* 医院webservice推送方法
|
||||
*
|
||||
* @author wyb
|
||||
*/
|
||||
public interface HospitalWsMethod {
|
||||
/**
|
||||
* 电子病历提交信息推送
|
||||
*/
|
||||
String WS_RECORD_SUBMIT = "WS_RECORD_SUBMIT";
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.docus.server.message.controller;
|
||||
|
||||
import com.docus.server.message.consts.InteractiveMethod;
|
||||
import com.docus.server.message.dto.Message;
|
||||
import com.docus.server.message.service.UnifyMessageService;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
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.RestController;
|
||||
|
||||
/**
|
||||
* 消息接收控制
|
||||
*
|
||||
* @author wyb
|
||||
*/
|
||||
@Api("消息推送")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/message/push")
|
||||
public class MessagePushController {
|
||||
private UnifyMessageService unifyMessageService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(InteractiveMethod.HTTP)
|
||||
public void setUnifyMessageService(UnifyMessageService unifyMessageService) {
|
||||
this.unifyMessageService = unifyMessageService;
|
||||
}
|
||||
|
||||
@PostMapping("/do")
|
||||
public String pushInformation(@RequestBody Message message) {
|
||||
return unifyMessageService.pushInformation(message.getMethod(), message.getMessage());
|
||||
}
|
||||
}
|
@ -1,35 +1,32 @@
|
||||
package com.docus.server.message.controller;
|
||||
|
||||
import com.docus.server.message.consts.InteractiveMethod;
|
||||
import com.docus.infrastructure.web.api.ResultCode;
|
||||
import com.docus.server.message.dto.Message;
|
||||
import com.docus.server.message.service.UnifyMessageService;
|
||||
import com.docus.server.message.dto.MessageResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
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.RestController;
|
||||
|
||||
/**
|
||||
* 消息接收控制
|
||||
*
|
||||
* @author wyb
|
||||
*/
|
||||
@Api("")
|
||||
@Api("消息接收")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/api/message")
|
||||
@RequestMapping("/message/receive")
|
||||
public class MessageReceiveController {
|
||||
private UnifyMessageService unifyMessageService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(InteractiveMethod.HTTP)
|
||||
public void setUnifyMessageService(UnifyMessageService unifyMessageService) {
|
||||
this.unifyMessageService = unifyMessageService;
|
||||
}
|
||||
|
||||
@PostMapping("/receive")
|
||||
public String receiveMessage(Message message){
|
||||
return unifyMessageService.receive(message.getMethod(),message.getMessage());
|
||||
@PostMapping("/wsRecordSubmit/do")
|
||||
@ApiOperation("消息接收测试")
|
||||
public MessageResponse receiveMessage(@RequestBody Message message) {
|
||||
System.out.println("wsRecordSubmit" + message);
|
||||
return new MessageResponse(ResultCode.SUCCESS.getCode(), "成功接收到了!");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.docus.server.message.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author wyb
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class MessageResponse {
|
||||
private Integer respCode;
|
||||
private String respMessage;
|
||||
|
||||
public MessageResponse(Integer respCode, String respMessage) {
|
||||
this.respCode = respCode;
|
||||
this.respMessage = respMessage;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.docus.server.message.enums;
|
||||
|
||||
import com.docus.infrastructure.core.db.enums.IIntegerEnum;
|
||||
|
||||
public enum DataFormatEnum implements IIntegerEnum {
|
||||
XML(1, "XML"), JSON(2, "JSON");
|
||||
Integer value;
|
||||
String display;
|
||||
|
||||
DataFormatEnum(Integer value, String display) {
|
||||
this.value = value;
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay() {
|
||||
return this.display;
|
||||
}
|
||||
|
||||
public static DataFormatEnum fromValue(Integer value) {
|
||||
try {
|
||||
return (DataFormatEnum) IIntegerEnum.fromValue(DataFormatEnum.class, value);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.docus.server.message.result;
|
||||
|
||||
import com.docus.server.message.enums.DataFormatEnum;
|
||||
|
||||
public class MessageInfo {
|
||||
private final DataFormatEnum messageFormat;
|
||||
private final String message;
|
||||
|
||||
public MessageInfo(DataFormatEnum dataFormatEnum, String message) {
|
||||
this.messageFormat = dataFormatEnum;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public DataFormatEnum getMessageFormat() {
|
||||
return messageFormat;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.docus.server.message.result;
|
||||
|
||||
import com.docus.core.util.DateUtil;
|
||||
import com.docus.core.util.Func;
|
||||
import com.docus.server.message.util.IdUtil;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public enum ParametersEnum {
|
||||
DATE("DATE", DateUtil.format(new Date(), "yyyy-MM-dd")),
|
||||
DATE_NO_CONNECT("DATE_NO_CONNECT", DateUtil.format(new Date(), "yyyyMMdd")),
|
||||
DATE_TIME("DATE_TIME", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss")),
|
||||
DATE_TIME_NO_CONNECT("DATE_TIME_NO_CONNECT", DateUtil.format(new Date(), "yyyyMMddHHmmss")),
|
||||
STANDARD_UUID("STANDARD_UUID", IdUtil.standardUUID()),
|
||||
STANDARD_NO_CONNECT("STANDARD_NO_CONNECT", Func.randomUUID()),
|
||||
;
|
||||
String type;
|
||||
String param;
|
||||
|
||||
ParametersEnum(String type, String param) {
|
||||
this.type = type;
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
public String getParam() {
|
||||
return param;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.docus.server.message.result;
|
||||
|
||||
public class PlaceHolder {
|
||||
/**
|
||||
* 表达式路径
|
||||
*/
|
||||
private final String path;
|
||||
/**
|
||||
* 完整占位字符
|
||||
*/
|
||||
private final String placeHolder;
|
||||
|
||||
public PlaceHolder(String path, String placeHolder) {
|
||||
this.path = path;
|
||||
this.placeHolder = placeHolder;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getPlaceHolder() {
|
||||
return placeHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlaceHolder{" +
|
||||
"path='" + path + '\'' +
|
||||
", placeHolder='" + placeHolder + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,12 @@
|
||||
package com.docus.server.message.service;
|
||||
|
||||
import javax.jws.WebService;
|
||||
|
||||
/**
|
||||
* @author WYBDEV
|
||||
*/
|
||||
@WebService
|
||||
public interface SdWebServiceUnifyMessageService {
|
||||
|
||||
String pushInformation(String message);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.docus.server.message.service.impl;
|
||||
|
||||
import com.docus.server.message.consts.HospitalWsMethod;
|
||||
import com.docus.server.message.consts.InteractiveMethod;
|
||||
import com.docus.server.message.service.SdWebServiceUnifyMessageService;
|
||||
import com.docus.server.message.service.UnifyMessageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author WYBDEV
|
||||
*/
|
||||
@Service(HospitalWsMethod.WS_RECORD_SUBMIT)
|
||||
public class SdWebServiceUnifyMessageServiceImpl implements SdWebServiceUnifyMessageService {
|
||||
|
||||
private UnifyMessageService unifyMessageService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier(InteractiveMethod.WS)
|
||||
public void setUnifyMessageService(UnifyMessageService unifyMessageService) {
|
||||
this.unifyMessageService = unifyMessageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pushInformation(String message) {
|
||||
return unifyMessageService.pushInformation(HospitalWsMethod.WS_RECORD_SUBMIT,message);
|
||||
}
|
||||
}
|
@ -1,16 +1,61 @@
|
||||
package com.docus.server.message.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.docus.core.util.Func;
|
||||
import com.docus.infrastructure.web.api.ResultCode;
|
||||
import com.docus.server.message.config.WsMessageForwardConfig;
|
||||
import com.docus.server.message.consts.InteractiveMethod;
|
||||
import com.docus.server.message.dto.Message;
|
||||
import com.docus.server.message.dto.MessageResponse;
|
||||
import com.docus.server.message.enums.DataFormatEnum;
|
||||
import com.docus.server.message.result.MessageInfo;
|
||||
import com.docus.server.message.result.ResultUtil;
|
||||
import com.docus.server.message.service.UnifyMessageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author WYBDEV
|
||||
*/
|
||||
@Service(InteractiveMethod.WS)
|
||||
@Slf4j
|
||||
public class WebServiceUnifyMessageServiceImpl implements UnifyMessageService {
|
||||
@Override
|
||||
public String receive(String method,String message) {
|
||||
return null;
|
||||
public String pushInformation(String method, String message) {
|
||||
Message messageObj = new Message(method, message);
|
||||
WsMessageForwardConfig.WsMessageForward wsMessageForward = WsMessageForwardConfig.wsMessageForward(method);
|
||||
if (wsMessageForward == null || Func.isEmpty(wsMessageForward.getUrls())) {
|
||||
return "方法匹配错误!";
|
||||
}
|
||||
DataFormatEnum dataFormatEnum = DataFormatEnum.fromValue(wsMessageForward.getMessageDataType());
|
||||
if (dataFormatEnum == null) {
|
||||
return "格式匹配错误!";
|
||||
}
|
||||
try {
|
||||
List<MessageResponse> responseLis = new ArrayList<>();
|
||||
for (String url : wsMessageForward.getUrls()) {
|
||||
String resp = HttpUtil.post(url, Func.toJson(messageObj));
|
||||
responseLis.add(Func.readJson(resp, MessageResponse.class));
|
||||
}
|
||||
for (MessageResponse response : responseLis) {
|
||||
if (ResultCode.FAILED.getCode().equals(response.getRespCode())) {
|
||||
return response.getRespMessage();
|
||||
}
|
||||
}
|
||||
responseLis = responseLis.stream().filter(item -> Func.isNotEmpty(item.getRespCode())).collect(Collectors.toList());
|
||||
if (Func.isEmpty(responseLis)) {
|
||||
throw new RuntimeException("未收到成功和失败的返回结果!");
|
||||
}
|
||||
return responseLis.get(0).getRespMessage();
|
||||
} catch (Exception ex) {
|
||||
// save(method,message);
|
||||
log.error(ex.getMessage(), ex);
|
||||
MessageInfo messageInfo = new MessageInfo(dataFormatEnum, message);
|
||||
return ResultUtil.dynamicParameterReplace(messageInfo, wsMessageForward.getErrorResult());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue