对接远端体检信息

连接远端平台——获取信息——对接比较——存入本地数据

与远端平台对接

1、访问接口

image.png

跳转到DAO层,获取数据
image.png

2、条件参数

条件参数都存在ProcedureCpEnum枚举类中

  1. public enum ProcedureCpEnum {
  2. /**查询类型*/
  3. CLOUD_PHYSICAL_LIST("体检套餐查询","clpList","{ call usp_web_webtrans_CTJYW001() }"),
  4. CLOUD_PHYSICAL_DETAIL("体检套餐明细查询","clpdetial","{ call usp_web_webtrans_CTJYW002_1(?) }"),
  5. CLOUD_PHYSICAL_DETAIL_ITEM("体检套餐内收费项目查询","clpdetialitem","{ call usp_web_webtrans_CTJYW002_2(?) }"),
  6. CLOUD_PHYSICAL_OTHER_POJB("获取所有收费项目查询","clpotherprjb","{ call usp_web_webtrans_CTJYW003() }"),
  7. CLOUD_PHYSICAL_ORDER("获取体检订单列表","clporder","{ call usp_web_webtrans_CTJYW004_1(?,?,?,?,?) }"),
  8. CLOUD_PHYSICAL_PACKAGE_LIST("根据体检编号获取项目列表","clppackagelist","{ call usp_web_webtrans_CTJYW004_2(?,?) }"),
  9. CLOUD_PHYSICAL_SCHEDULE("体检排班查询","clpschedule","{ call usp_web_webtrans_CTJYW017(?,?,?) }"),
  10. /**操作类型*/
  11. CLOUD_PHYSICAL_APPOINT("体检预约","clpappoint","{ call usp_web_webtrans_BTJYW001(?,?,?,?,?,?,?,?,?,?,?,?,?,?) }"),
  12. CLOUD_PHYSICAL_APPOINT_CANCEL("取消体检预约","clpappointcal","{ call usp_web_webtrans_BTJYW003(?,?) }");
  13. }

包含备注、返回体名、sql语句:
call uspweb_webtrans_CTJYW001()中的call就是执行sql server语句,usp_web_webtrans_CTJYW001语句名就在远端的sql脚本中(不用咋们自己写_)。

之后通过ConnectDBCallProUtil工具类调用远程交互。

3、远程数据库交互

代码示例:

  1. /**
  2. * 连接打开远程sqlserver数据库,执行存储过程
  3. * @param sql
  4. * @param params
  5. * @return
  6. */
  7. public static List<Object> callProcedure(String sql, Object[] params){
  8. List<Object> listResult = new ArrayList<>();
  9. logger.info("call sql= {},",sql);
  10. SessionFactory sessionFactory = (SessionFactory) SpringContextUtil.getBean("sessionFactoryServer");
  11. Session session = sessionFactory.openSession();
  12. session.beginTransaction();
  13. try {
  14. SQLQuery query = session.createSQLQuery(sql);
  15. if (null != params) {
  16. int i = 0;
  17. for (Object param : params) {
  18. if(null == param){
  19. query.setString(i,null);
  20. } else {
  21. if (param instanceof String) {
  22. query.setString(i, param.toString());
  23. } else if (param instanceof Integer) {
  24. query.setInteger(i, ((Integer) param).intValue());
  25. }
  26. }
  27. i++;
  28. }
  29. }
  30. listResult = query.list();
  31. logger.info("call sql= {} =,listResult size={}", sql, listResult.size());
  32. //提交对数据的操作
  33. session.getTransaction().commit();
  34. closeSession(session);
  35. } catch (Exception e) {
  36. logger.error("执行存储过程异常={}",e);
  37. closeSession(session);
  38. } finally {
  39. closeSession(session);
  40. }
  41. return listResult;
  42. }

以上是连接打开远程sqlserver数据库,执行存储过程

  • 先连接一个session工厂,开一个session连接资源

    SessionFactory sessionFactory = (SessionFactory) SpringContextUtil.getBean("sessionFactoryServer");
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    
  • 打开query,拼接参数

    SQLQuery query = session.createSQLQuery(sql);
    
  • 执行查询

    listResult = query.list();
    //提交对数据的操作
    session.getTransaction().commit();
    
  • 一定要记得关闭资源,不然一直申请,会达到一个上限,导致申请不到session ```java closeSession(session); } catch (Exception e) { logger.error(“执行存储过程异常={}”,e); closeSession(session); } finally { closeSession(session); }

private static void closeSession(Session session){ if(session.isOpen()){ session.close(); } } ```

与本地数据处理

_