Browse Source

上传https工具类 代码

chenweida 9 years ago
parent
commit
2db2e93315

+ 4 - 1
Hos-Resource-Rest/src/main/java/com/yihu/hos/gateway/control/GatewayControl.java

@ -48,7 +48,10 @@ public class GatewayControl {
        RestResponseResult restResponseResult = new RestResponseResult();
        try {
            BeanUtils.populate(restRequsetResult, request.getParameterMap());
            //---start  扩展type和data两个参数 作用于API和param一样
            restRequsetResult.setApi(restRequsetResult.getType());
            restRequsetResult.setParam(restRequsetResult.getData());
            //---end
            //判断参数是否为空
            paramsIsNotNull(restRequsetResult.getApi());
            //根据API得到资源对象

+ 31 - 11
Hos-Resource-Rest/src/main/java/com/yihu/hos/gateway/model/rest/RestRequsetResult.java

@ -16,6 +16,10 @@ public class RestRequsetResult implements Serializable {
    private String api;
    private String param;
    private String requestId;
    //以下参数是作为全流程对接情况处理的参数---start
    private String type;//作用和api参数一样
    private String data;//作用和data参数一样
    //---end
    public String getApi() {
        return api;
@ -41,6 +45,22 @@ public class RestRequsetResult implements Serializable {
        this.requestId = requestId;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    @Override
    public String toString() {
        return "{" +
@ -51,16 +71,16 @@ public class RestRequsetResult implements Serializable {
    }
    public static void main(String[] args) {
        InvokeRequest r=new InvokeRequest(new Url("127.0.0.1",8891),"com.yihu.hos.gateway.control.rpc.IResourceRpc","transport",String.class);
         r.add(String.class,"你好");
         r.setSendTimeOutMills(3000);//设置默认的超时时间
         r.setSyncMode();//设置调用模式为同步模式
         try {
             Object s=Rpc.invoke(r);
             System.out.println(s.toString());
           } catch (Exception e1) {
                e1.printStackTrace();
         }//调用并返回结果
        InvokeRequest r = new InvokeRequest(new Url("127.0.0.1", 8891), "com.yihu.hos.gateway.control.rpc.IResourceRpc", "transport", String.class);
        r.add(String.class, "你好");
        r.setSendTimeOutMills(3000);//设置默认的超时时间
        r.setSyncMode();//设置调用模式为同步模式
        try {
            Object s = Rpc.invoke(r);
            System.out.println(s.toString());
        } catch (Exception e1) {
            e1.printStackTrace();
        }//调用并返回结果
    }
}

+ 68 - 26
Hos-Resource-Rest/src/main/java/com/yihu/hos/qlc/controller/QLCController.java

@ -5,6 +5,7 @@ import com.yihu.hos.config.Config;
import com.yihu.hos.gateway.model.rest.RestResponseResult;
import com.yihu.hos.gateway.util.RPCUtil;
import com.yihu.hos.resource.util.httpclient.HttpClientUtil;
import com.yihu.hos.resource.viewModel.SQLResponResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -48,16 +49,23 @@ public class QLCController {
     */
    @RequestMapping(value = "/queryUserInfo", method = RequestMethod.POST)
    @ApiOperation(value = "挂号事件推送", response = Object.class, produces = "application/json", notes = "院方挂号事件推送")
    public RestResponseResult queryUserInfo(@ApiParam(value = "事件类型:门诊、住院", required = true) @RequestParam(value = "EventType") String EventType,
                                            @ApiParam(value = "事件编码:门诊号、住院号", required = true) @RequestParam(value = "EventNo") String EventNo,
                                            @ApiParam(value = "卡类型", required = true) @RequestParam(value = "CardType") String CardType,
                                            @ApiParam(value = "卡号", required = true) @RequestParam(value = "CardNo") String CardNo,
                                            @ApiParam(value = "PatientId", required = true) @RequestParam(value = "PatientId") String PatientId,
                                            @ApiParam(value = "医院ID", required = true) @RequestParam(value = "HospitalId") String HospitalId,
                                            HttpServletRequest request) {
        RestResponseResult restResponseResult = new RestResponseResult();
    public SQLResponResult queryUserInfo(@ApiParam(value = "事件类型:门诊、住院", required = true) @RequestParam(value = "EventType") String EventType,
                                         @ApiParam(value = "事件编码:门诊号、住院号", required = true) @RequestParam(value = "EventNo") String EventNo,
                                         @ApiParam(value = "卡类型", required = true) @RequestParam(value = "CardType") String CardType,
                                         @ApiParam(value = "卡号", required = true) @RequestParam(value = "CardNo") String CardNo,
                                         @ApiParam(value = "PatientId", required = true) @RequestParam(value = "PatientId") String PatientId,
                                         @ApiParam(value = "医院ID", required = true) @RequestParam(value = "HospitalId") String HospitalId,
                                         HttpServletRequest request) {
        SQLResponResult restResponseResult = new SQLResponResult();
        Object s = null;
        try {
            isEmpty(EventType, "EventType为空");
            isEmpty(EventNo, "EventNo为空");
            isEmpty(CardType, "CardType为空");
            isEmpty(CardNo, "CardNo为空");
            isEmpty(PatientId, "PatientId为空");
            isEmpty(HospitalId, "HospitalId为空");
            String param = "<Req><TransactionCode>5001</TransactionCode><Data><CardType>" + CardType + "</CardType><CardNo>" + CardNo + "</CardNo><PatientId>" + PatientId + "</PatientId></Data></Req>";
            String apiparam = "{\"ChannelId\"=\"" + Config.channelId + "\"," +
                    "\"ParamType\"=1," +
@ -83,40 +91,51 @@ public class QLCController {
                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);
                String monogoUrl = httpClientUtil.doPost(Config.monogoUrl, params, null, null);
                monogoUrlValid(monogoUrl);
                //出發採集上傳
                params = new HashMap<String, Object>();
                params.put("orgCode", HospitalId);
                params.put("cardNo", CardNo);
                params.put("eventNo", PatientId);
                httpClientUtil.doPost(Config.startCollect, params, null, null);
                String startCollect = httpClientUtil.doPost(Config.startCollect, params, null, null);
                monogoUrlValid(startCollect);
            } else {
                throw new Exception("RPC返回RespCode:" + root.element("RespCode").getText());
                throw new Exception(s.toString());
            }
        } catch (Exception e) {
            restResponseResult.setResponseCode("20000");
            restResponseResult.setResponseMessage(e.getMessage() + "RPC:返回" + s);
            restResponseResult.setStatus("1");
            restResponseResult.setStatusInfo(e.getMessage() + "RPC:返回" + s);
            return restResponseResult;
        }
        return restResponseResult;
    }
    /**
     * 院方_检查/检验报告单推送---数据说明
     * localhost:8890/gateway/transfer?api=patientInformationPush&param={CardType:"",CardNo:"000021341249",ReportType:"0",ReportId:"201405228-A-110B",State:"2",HospitalId:"1026333"}&requestId="目前没用随便写"
     */
    @RequestMapping(value = "/patientInformation", method = RequestMethod.POST)
    @ApiOperation(value = "检查/检验报告单推送-", response = Object.class, produces = "application/json", notes = "检查/检验报告单推送-")
    public RestResponseResult patientInformation(@ApiParam(value = "卡类型", required = true) @RequestParam(value = "CardType") String CardType,
                                                 @ApiParam(value = "卡号", required = true) @RequestParam(value = "CardNo") String CardNo,
                                                 @ApiParam(value = "报告单类型1检验报告2检查报告", required = true) @RequestParam(value = "ReportType") String ReportType,
                                                 @ApiParam(value = "报告单号", required = true) @RequestParam(value = "ReportId") String ReportId,
                                                 @ApiParam(value = "报告单状态1 报告未出 2报告已出", required = true) @RequestParam(value = "State") String State,
                                                 @ApiParam(value = "医院ID", required = true) @RequestParam(value = "HospitalId") String HospitalId,
                                                 HttpServletRequest request) {
        RestResponseResult restResponseResult = new RestResponseResult();
    public SQLResponResult patientInformation(@ApiParam(value = "卡类型", required = true) @RequestParam(value = "CardType") String CardType,
                                              @ApiParam(value = "卡号", required = true) @RequestParam(value = "CardNo") String CardNo,
                                              @ApiParam(value = "报告单类型1检验报告2检查报告", required = true) @RequestParam(value = "ReportType") String ReportType,
                                              @ApiParam(value = "报告单号", required = true) @RequestParam(value = "ReportId") String ReportId,
                                              @ApiParam(value = "报告单状态1 报告未出 2报告已出", required = true) @RequestParam(value = "State") String State,
                                              @ApiParam(value = "医院ID", required = true) @RequestParam(value = "HospitalId") String HospitalId,
                                              HttpServletRequest request) {
        SQLResponResult restResponseResult = new SQLResponResult();
        Object s = null;
        try {
            isEmpty(CardType, "CardType为空");
            isEmpty(CardNo, "CardNo为空");
            isEmpty(ReportType, "ReportType为空");
            isEmpty(ReportId, "ReportId为空");
            isEmpty(State, "State为空");
            isEmpty(HospitalId, "HospitalId为空");
            if ("1".equals(State)) {
                throw new Exception("报告未出,结束");
            }
@ -158,24 +177,26 @@ public class QLCController {
                        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);
                        String monogoUrl = httpClientUtil.doPost(Config.monogoUrl, params, null, null);
                        monogoUrlValid(monogoUrl);
                        //出發採集上傳
                        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);
                        String startCollect = httpClientUtil.doPost(Config.startCollect, params, null, null);
                        monogoUrlValid(startCollect);
                    }
                } else {
                    throw new Exception("RPC返回数据格式不合法:" + dataXml.getText());
                }
            } else {
                throw new Exception("RPC返回RespCode:" + root.element("RespCode").getText());
                throw new Exception(s.toString());
            }
        } catch (Exception e) {
            restResponseResult.setResponseCode("20000");
            restResponseResult.setResponseMessage(e.getMessage() + "RPC:返回" + s);
            restResponseResult.setStatus("2");
            restResponseResult.setStatusInfo(e.getMessage() + "RPC:返回" + s);
            return restResponseResult;
        }
        return restResponseResult;
@ -237,4 +258,25 @@ public class QLCController {
        return obj;
    }
    /**
     * 判断是否为空
     *
     * @param EventType
     * @param message
     * @throws Exception
     */
    private void isEmpty(String EventType, String message) throws Exception {
        if (StringUtils.isEmpty(EventType)) {
            throw new Exception(message);
        }
    }
    private boolean monogoUrlValid(String monogoUrl) throws Exception {
        JSONObject jo = JSONObject.fromObject(monogoUrl);
        if ("true".equals(jo.get("successFlg"))) {
            return true;
        } else {
            throw new Exception(jo.get("message").toString());
        }
    }
}

+ 37 - 0
Hos-Resource-Rest/src/main/java/com/yihu/hos/resource/viewModel/SQLResponResult.java

@ -0,0 +1,37 @@
package com.yihu.hos.resource.viewModel;
/**
 * Created by Administrator on 2016/4/25.
 */
public class SQLResponResult {
    /**
     * 0:接口数据请求正常
     * ≠0:接口响应数据异常
     */
    private String status = "0";
    /**
     * 当出错的时候,返回出错的说明,如下:
     * {
     * "status": 1,
     * "statusInfo": "传入参数错误",
     * "data": []
     * }
     */
    private String statusInfo;
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getStatusInfo() {
        return statusInfo;
    }
    public void setStatusInfo(String statusInfo) {
        this.statusInfo = statusInfo;
    }
}