Selaa lähdekoodia

RPC网关提交

chenweida 9 vuotta sitten
vanhempi
commit
6016acd220

+ 76 - 20
Hos-Resource-Rest/src/main/java/com/yihu/hos/gateway/control/rpc/impl/ResourceRpcImpl.java

@ -16,6 +16,7 @@ import net.sf.json.xml.XMLSerializer;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.*;
@ -29,6 +30,7 @@ public class ResourceRpcImpl implements IResourceRpc {
    @Override
    public String transport(String RPCRequestXml) {
        RPCResponseResult r = null;
        try {
            //解析xml
@ -46,30 +48,67 @@ public class ResourceRpcImpl implements IResourceRpc {
                String cardNo = root.element("Data").element("CardNo").toString();
                String cardType = root.element("Data").element("CardType").toString();
                String patientId = root.element("Data").element("PatientId").toString();
                String hospitalId = root.element("Data").element("HospitalId").toString();
                if (StringUtils.isEmpty(cardNo)) {
                    throw new Exception("cardNo为空");
                }
                if (StringUtils.isEmpty(cardType)) {
                    throw new Exception("cardType为空");
                }
                if (StringUtils.isEmpty(patientId)) {
                    throw new Exception("patientId为空");
                }
                if (StringUtils.isEmpty(hospitalId)) {
                    throw new Exception("HospitalId为空");
                }
                //映射orgcode
                String orgCode = getOrgCodeBy(hospitalId);
                //查询病人基本信息
                patientInformation(cardNo, cardType, patientId);
                patientInformation(cardNo, cardType, patientId,orgCode);
            } else if (trancode.equals(Constant.PUSHREPORT)) {
                //检查检验报告
                String reportType = root.element("Data").element("ReportType").toString();
                String reportId = root.element("Data").element("ReportId").toString();
                pushreport(reportType, reportId);
                String cardNo = root.element("Data").element("CardNo").toString();
                String cardType = root.element("Data").element("CardType").toString();
                String hospitalId = root.element("Data").element("HospitalId").toString();
                if (StringUtils.isEmpty(reportType)) {
                    throw new Exception("reportType为空");
                }
                if (StringUtils.isEmpty(reportId)) {
                    throw new Exception("reportId为空");
                }
                if (StringUtils.isEmpty(cardNo)) {
                    throw new Exception("cardNo为空");
                }
                if (StringUtils.isEmpty(cardType)) {
                    throw new Exception("cardType为空");
                }
                if (StringUtils.isEmpty(hospitalId)) {
                    throw new Exception("HospitalId为空");
                }
                //映射orgcode
                String orgCode = getOrgCodeBy(hospitalId);
                pushreport(reportType, reportId, cardNo, cardType, orgCode);
            }
            RPCResponseResult r = RPCResponseResult.success();
            r = RPCResponseResult.success();
        } catch (Exception e) {
            r = RPCResponseResult.error();
            r.setRespMessage(e.getMessage());
            r.setRespCode("20001");
        }
        return "你也好";
        return JSONObject.fromObject(r).toString();
    }
    //查询病人基本信息
    private void patientInformation(String cardNo, String cardType, String patientId) throws Exception {
    private void patientInformation(String cardNo, String cardType, String patientId,String hospitalId) throws Exception {
        String param = "<Req><TransactionCode>1001</TransactionCode>" +
                "<Data>" +
                "<CardType>"+cardType+"</CardType>" +
                "<CardNo>"+cardNo+"</CardNo>" +
                "<PatientName>zhengmy" +"</PatientName>" +
                "<CardType>" + cardType + "</CardType>" +
                "<CardNo>" + cardNo + "</CardNo>" +
                "<PatientId>" + patientId + "</PatientId>" +
                "</Data>" +
                "</Req>";
        String apiparam = "{\"ChannelId\"=\"100123\"," +
@ -78,7 +117,7 @@ public class ResourceRpcImpl implements IResourceRpc {
                "\"Guid\"=\"" + "00000001111111" + "\"," +
                "\"V\"=\"3.0.0\"," +
                "\"OutType\"=0n ," +
                "\"HospitalId\"=\"1026333\"}";
                "\"HospitalId\"=\""+hospitalId+"\"}";
        Object s = RPCUtil.getRPCData("ZEUS.HosHOPWs.QueryUserInfo", apiparam);
        //解析xml
        SAXReader saxReader = new SAXReader();
@ -86,12 +125,22 @@ public class ResourceRpcImpl implements IResourceRpc {
        Element root = document.getRootElement();
        if ("10000".equals(root.element("RespCode"))) {
            //xml轉json
            Element dataXML = root.element("Data");
            JSONObject obj = xml2json(root.element("Data"));
            obj.put("CardType", cardType);
            obj.put("CardNo", cardNo);
            obj.put("PatientId", patientId);
            obj.put("OrgCode", hospitalId);
            //調用接口存入mongo
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("dataset", "HDSA00_01");
            params.put("data", obj.toString());
            httpClientUtil.doPost(Config.monogoUrl, params, null, null);
            //出發採集上傳
            params = new HashMap<String, Object>();
            params.put("orgCode", hospitalId);
            params.put("cardNo", cardNo);
            params.put("eventNo", patientId);
            httpClientUtil.doPost(Config.startCollect, params, null, null);
        }
    }
@ -103,7 +152,7 @@ public class ResourceRpcImpl implements IResourceRpc {
    }
    //检查检验报告
    private void pushreport(String reportType, String reportId) throws Exception {
    private void pushreport(String reportType, String reportId, String cardNo, String cardType, String hospitalId) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String data =
                "<Req>" +
@ -119,7 +168,7 @@ public class ResourceRpcImpl implements IResourceRpc {
                "\"Guid\"=\"" + "00000001111111" + "\"," +
                "\"V\"=\"3.0.0\"," +
                "\"OutType\"=0," +
                "\"HospitalId\"=\"1026333\"}";
                "\"HospitalId\"=\""+hospitalId+"\"}";
        Object s = RPCUtil.getRPCData("ZEUS.HosHOPWs.GetReportInfo", apiparam);
        //解析xml
        SAXReader saxReader = new SAXReader();
@ -135,22 +184,29 @@ public class ResourceRpcImpl implements IResourceRpc {
            if (elements != null && elements.size() > 0) {
                for (Object obj1 : elements) {
                    Element data1XML = (Element) obj1;
                    //从表节点
                    JSONObject objData = xml2json(data1XML);
                    objData.put("CardType", cardType);
                    objData.put("CardNo", cardNo);
                    objData.put("ReportId", reportId);
                    objData.put("ReportType", reportType);
                    objData.put("OrgCode", hospitalId);
                    //添加主表的所有信息
                    objData.putAll(xml2json(dataXml));
                    //調用接口存入mongo
                    Map<String, Object> params = new HashMap<String, Object>();
                    params.put("dataset", "HDSD01_01");
                    params.put("data", objData.toString());
                    httpClientUtil.doPost(Config.monogoUrl, params, null, null);
                    //出發採集上傳
                    params = new HashMap<String, Object>();
                    params.put("orgCode", hospitalId);
                    params.put("cardNo", cardNo);
                    params.put("eventNo", StringUtils.isEmpty(objData.get("ClinicNo")) ? objData.get("HosUserNo") : objData.get("ClinicNo"));
                    httpClientUtil.doPost(Config.startCollect, params, null, null);
                }
            }
            obj.put(root.getName(), iterateElement(root));
            String jsonString = obj.toString();
            //調用接口存入mongo
            Map<String, Object> params = new HashMap<String, Object>();
            httpClientUtil.doPost(Config.monogoUrl, params, null, null);
            //出發採集上傳
            params = new HashMap<String, Object>();
            httpClientUtil.doPost(Config.startCollect, params, null, null);
        }
    }

+ 41 - 15
Hos-Resource-Rest/src/main/java/com/yihu/hos/gateway/util/RPCUtil.java

@ -53,22 +53,17 @@ public class RPCUtil {
        }
        return "";
    }
    /*
    public static void main(String[] args) throws Exception {
        String apiName = "ZEUS.HosHOPWs.GetReportList";
        String apiName = "report.ReportWs.GetReportList";
      String  param = "<Req><TransactionCode>1001</TransactionCode>" +
                "<Data>" +
                "<CardType>1</CardType>" +
                "<CardNo>123</CardNo>" +
                "<StartDate>2016-04-19</StartDate>" +
                "<EndDate>2016-08-19</EndDate>" +
                "<Mobile>18559991897</Mobile>" +
                "<PatientName>zhengmy" +
                "</PatientName>" +
                "<ReportType>1</ReportType>" +
                "</Data>" +
                "</Req>";
      String  param = "<Req> \n" +
              "<TransactionCode></TransactionCode>\n" +
              "<Data>\n" +
              "<ReportId>8F5F14C2-FAB8-4CB5-BB91-AECF0EC64E69</ReportId>\n" +
              "<ReportType>1</ReportType>\n" +
              "</Data>\n" +
              "</Req>";
        String apiparam = "{\"ChannelId\"=\"100123\"," +
                "\"ParamType\"=1," +
                "\"Params\"=\"" + param + "\"," +
@ -78,8 +73,39 @@ public class RPCUtil {
                "\"HospitalId\"=\"1026333\"}";
        String result = null;
        result = ServiceBus.getInstance(
                "172.18.20.123:8085",
                "172.18.20.21:2181",
                "EsbCloud").call(apiName, apiparam);
        System.out.println("返回的数据:"+result);
    }
*/
    /**
     *
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String apiName="ZEUS.HosHOPWs.GetReportInfo";
        String param = "";
        param = "<Req><TransactionCode>5001</TransactionCode><Data><ReportId>8F5F14C2-FAB8-4CB5-BB91-AECF0EC64E69</ReportId><ReportType>1</ReportType></Data></Req>";
         String apiparam = "{\"ChannelId\"=\"100123\"," +
                "\"ParamType\"=1," +
                "\"Params\"=\"" + param + "\"," +
                "\"Guid\"=\"" + "00000001111111" + "\"," +
                "\"V\"=\"3.0.0\"," +
                "\"OutType\"=1," +
                "\"HospitalId\"=\"1026333\"}";
        String result = null;
        try {
            result = ServiceBus.getInstance(
                    "172.18.20.21:2181",
                    "EsbCloud").call(apiName, apiparam);
            System.out.println("返回的数据:"+result);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("result="+result);
    }
    /*
    public static void main(String[] args) {

+ 1 - 1
Hos-Resource-Rest/src/main/resources/rpc.properties

@ -2,4 +2,4 @@ rpc.url=172.18.20.123:8085
rpc.appId=EsbCloud
http.monogourl=http://localhost:8080/datapush/datapush
http.startCollect=http://localhost:8080/datapush/datapush
http.startCollect=http://localhost:8080/crawler/patient

BIN
Hos-Resource-Rest/对接文档参数说明.docx