ExcuteService.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package com.yihu.ehr.ws;
  2. import com.yihu.ehr.dbhelper.jdbc.DBHelper;
  3. import com.yihu.ehr.model.DataSource;
  4. import com.yihu.ehr.model.WSReturnModel;
  5. import com.yihu.ehr.util.operator.StringUtil;
  6. import org.apache.commons.dbcp2.BasicDataSource;
  7. import org.springframework.jdbc.core.JdbcTemplate;
  8. import org.springframework.util.ResourceUtils;
  9. import java.io.BufferedReader;
  10. import java.io.File;
  11. import java.io.FileReader;
  12. import java.io.IOException;
  13. /**
  14. * Created by Administrator on 2016/5/19.
  15. */
  16. public class ExcuteService {
  17. public static JdbcTemplate jdbcTemplate = null;
  18. public void initJDBC() throws Exception {
  19. if (jdbcTemplate == null) {
  20. //jdbc:oracle:thin:hos/hos@//172.19.103.71:1521/orcl
  21. //jdbc:mysql://172.19.103.71:1521/orcl?user=hos&password=hos&useUnicode=true&characterEncoding=UTF-8
  22. //jdbc:sqlserver://172.19.103.71:1521/orcl?user=hos&password=hos
  23. DBHelper dbTemp = new DBHelper();
  24. DataSource source = dbTemp.load(DataSource.class, "select * from system_datasource");
  25. String config = source.getConfig();
  26. BasicDataSource dasicDataSource = new BasicDataSource();
  27. if (config.contains("oracle")) {
  28. //oracle数据库
  29. dasicDataSource.setUrl(source.getConfig());
  30. dasicDataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
  31. String[] s1 = config.split("@");
  32. String[] s2 = s1[0].split(":");
  33. String[] s3 = s2[3].split("/");
  34. dasicDataSource.setUsername(s3[0]);
  35. dasicDataSource.setPassword(s3[1]);
  36. } else if (config.contains("mysql")) {
  37. //mysql数据库
  38. dasicDataSource.setUrl(source.getConfig());
  39. dasicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
  40. String[] s1 = config.split("\\?");
  41. String[] s2 = s1[1].split("&");
  42. dasicDataSource.setUsername(s2[0].split("=")[1]);
  43. dasicDataSource.setPassword(s2[1].split("=")[1]);
  44. } else if (config.contains("sqlserver")) {
  45. //sqlserver数据库
  46. dasicDataSource.setUrl(source.getConfig());
  47. dasicDataSource.setDriverClassName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
  48. String[] s1 = config.split("\\?");
  49. String[] s2 = s1[1].split("&");
  50. dasicDataSource.setUsername(s2[0].split("=")[1]);
  51. dasicDataSource.setPassword(s2[1].split("=")[1]);
  52. }
  53. jdbcTemplate = new JdbcTemplate();
  54. jdbcTemplate.setDataSource(dasicDataSource);
  55. }
  56. }
  57. /**
  58. * 执行sql语句
  59. *
  60. * @param sql
  61. * @return
  62. */
  63. public String excuteSQL(String TransactionCode,
  64. String sql) {
  65. WSReturnModel wsReturnModel = new WSReturnModel();
  66. wsReturnModel.setTransactionCode(TransactionCode);
  67. try {
  68. initJDBC();
  69. wsReturnModel.setData(jdbcTemplate.queryForList(sql));
  70. return WSReturnModel.toXml(wsReturnModel);
  71. } catch (Exception e1) {
  72. wsReturnModel.setTransactionCode("-30000");
  73. wsReturnModel.setRespMessage(e1.getMessage());
  74. return WSReturnModel.toXml(wsReturnModel);
  75. }
  76. }
  77. /**
  78. * 获取检查报告单的列表
  79. *
  80. * @param cardType
  81. * @param cardNo
  82. * @param startDate
  83. * @param endDate
  84. * @param mobile
  85. * @param reportType
  86. * @return
  87. */
  88. public String GetReportList(
  89. String TransactionCode,
  90. String cardType,
  91. String cardNo,
  92. String startDate,
  93. String endDate,
  94. String mobile,
  95. String reportType) {
  96. WSReturnModel wsReturnModel = new WSReturnModel();
  97. wsReturnModel.setTransactionCode(TransactionCode);
  98. try {
  99. //initJDBC();
  100. // StringBuffer sb = new StringBuffer("select * from HDSD01_01 where 1=1 ");
  101. //if (!StringUtils.isEmpty(endDate)) {
  102. // sb.append(" and HDSD00_05_026 < '" + endDate + "'");
  103. // }
  104. //if (!StringUtils.isEmpty(startDate)) {
  105. // sb.append(" and HDSD00_01_001 > '" + startDate + "'");
  106. // }
  107. //wsReturnModel.setData(jdbcTemplate.queryForList(sb.toString()));
  108. // return WSReturnModel.toXml(wsReturnModel);
  109. return getFileByPath("C:\\Documents and Settings\\Administrator\\桌面\\data\\GetReportList.xml");
  110. } catch (Exception e) {
  111. wsReturnModel.setTransactionCode("-30000");
  112. wsReturnModel.setRespMessage(e.getMessage());
  113. return WSReturnModel.toXml(wsReturnModel);
  114. }
  115. }
  116. /**
  117. * 检查报告单/检验报告单明细
  118. *
  119. * @param reportId
  120. * @param reportType
  121. * @return
  122. */
  123. public String GetReportInfo(
  124. String TransactionCode,
  125. String reportId,
  126. String reportType) {
  127. WSReturnModel wsReturnModel = new WSReturnModel();
  128. wsReturnModel.setTransactionCode(TransactionCode);
  129. try {
  130. /*
  131. initJDBC();
  132. StringBuffer sb = new StringBuffer("select * from HDSD01_01 where 1=1 ");
  133. if (!StringUtil.isEmpty(reportId)) {
  134. sb.append(" and HDSD00_05_026 < '" + reportId + "'");
  135. }
  136. if (!StringUtil.isEmpty(reportType)) {
  137. sb.append(" and HDSD00_01_001 > '" + reportType + "'");
  138. }*/
  139. // wsReturnModel.setData(jdbcTemplate.queryForList(sb.toString()));
  140. return getFileByPath("C:\\Documents and Settings\\Administrator\\桌面\\data\\GetReportInfo.xml");
  141. } catch (Exception e) {
  142. wsReturnModel.setTransactionCode("-30000");
  143. wsReturnModel.setRespMessage(e.getMessage());
  144. return WSReturnModel.toXml(wsReturnModel);
  145. }
  146. }
  147. public String QueryUserInfo(String TransactionCode, String CardType, String CardNo, String Mobile, String PatientId) {
  148. WSReturnModel wsReturnModel = new WSReturnModel();
  149. wsReturnModel.setTransactionCode(TransactionCode);
  150. try {
  151. /*
  152. initJDBC();
  153. StringBuffer sb = new StringBuffer("select * from HDSD01_01 where 1=1 ");
  154. if (!StringUtil.isEmpty(reportId)) {
  155. sb.append(" and HDSD00_05_026 < '" + reportId + "'");
  156. }
  157. if (!StringUtil.isEmpty(reportType)) {
  158. sb.append(" and HDSD00_01_001 > '" + reportType + "'");
  159. }*/
  160. // wsReturnModel.setData(jdbcTemplate.queryForList(sb.toString()));
  161. return getFileByPath("C:\\Documents and Settings\\Administrator\\桌面\\data\\QueryUserInfo.xml");
  162. } catch (Exception e) {
  163. wsReturnModel.setTransactionCode("-30000");
  164. wsReturnModel.setRespMessage(e.getMessage());
  165. return WSReturnModel.toXml(wsReturnModel);
  166. }
  167. }
  168. public static void main(String[] args) throws Exception {
  169. /*
  170. JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
  171. Client client = factory.createClient("http://172.19.103.71:8080/service/sql?wsdl");
  172. //Client client = factory.createClient("http://localhost:8080/service/sql?wsdl");
  173. try {
  174. Object[] result = client.invoke("ExcuteSQL", "10000", "select count(1) as COUNT,max(to_number(HDSD03_01_031)) as MAX_KEYVALUE from HDSC01_02 where 1=1 order by to_number(HDSD03_01_031)"); // 按照方法的参数来提供值
  175. if (result != null && result.length > 0) {
  176. System.out.println(result[0]); // 通过getUsername来获取对象的username属性
  177. }
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. }*/
  181. System.out.println(getFileByPath("C:\\Users\\Administrator\\Desktop\\getReportInfo.xml"));
  182. }
  183. public static String getFileByPath(String path) {
  184. BufferedReader reader = null;
  185. FileReader fileReader = null;
  186. try {
  187. File cfgFile = ResourceUtils.getFile(path);
  188. fileReader=new FileReader(cfgFile);
  189. reader = new BufferedReader(fileReader);
  190. String line;
  191. String strContent = "";
  192. while ((line = reader.readLine()) != null) {
  193. strContent += line;
  194. }
  195. return strContent;
  196. } catch (Exception e) {
  197. return "";
  198. } finally {
  199. if(reader!=null){
  200. try {
  201. reader.close();
  202. } catch (IOException e) {
  203. e.printStackTrace();
  204. }
  205. }
  206. if(fileReader!=null){
  207. try {
  208. fileReader.close();
  209. } catch (IOException e) {
  210. e.printStackTrace();
  211. }
  212. }
  213. }
  214. }
  215. }