123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- package com.yihu.ehr.ws;
- import com.yihu.ehr.dbhelper.jdbc.DBHelper;
- import com.yihu.ehr.model.DataSource;
- import com.yihu.ehr.model.WSReturnModel;
- import com.yihu.ehr.util.operator.StringUtil;
- import org.apache.commons.dbcp2.BasicDataSource;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.util.ResourceUtils;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- /**
- * Created by Administrator on 2016/5/19.
- */
- public class ExcuteService {
- public static JdbcTemplate jdbcTemplate = null;
- public void initJDBC() throws Exception {
- if (jdbcTemplate == null) {
- //jdbc:oracle:thin:hos/hos@//172.19.103.71:1521/orcl
- //jdbc:mysql://172.19.103.71:1521/orcl?user=hos&password=hos&useUnicode=true&characterEncoding=UTF-8
- //jdbc:sqlserver://172.19.103.71:1521/orcl?user=hos&password=hos
- DBHelper dbTemp = new DBHelper();
- DataSource source = dbTemp.load(DataSource.class, "select * from system_datasource");
- String config = source.getConfig();
- BasicDataSource dasicDataSource = new BasicDataSource();
- if (config.contains("oracle")) {
- //oracle数据库
- dasicDataSource.setUrl(source.getConfig());
- dasicDataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
- String[] s1 = config.split("@");
- String[] s2 = s1[0].split(":");
- String[] s3 = s2[3].split("/");
- dasicDataSource.setUsername(s3[0]);
- dasicDataSource.setPassword(s3[1]);
- } else if (config.contains("mysql")) {
- //mysql数据库
- dasicDataSource.setUrl(source.getConfig());
- dasicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
- String[] s1 = config.split("\\?");
- String[] s2 = s1[1].split("&");
- dasicDataSource.setUsername(s2[0].split("=")[1]);
- dasicDataSource.setPassword(s2[1].split("=")[1]);
- } else if (config.contains("sqlserver")) {
- //sqlserver数据库
- dasicDataSource.setUrl(source.getConfig());
- dasicDataSource.setDriverClassName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
- String[] s1 = config.split("\\?");
- String[] s2 = s1[1].split("&");
- dasicDataSource.setUsername(s2[0].split("=")[1]);
- dasicDataSource.setPassword(s2[1].split("=")[1]);
- }
- jdbcTemplate = new JdbcTemplate();
- jdbcTemplate.setDataSource(dasicDataSource);
- }
- }
- /**
- * 执行sql语句
- *
- * @param sql
- * @return
- */
- public String excuteSQL(String TransactionCode,
- String sql) {
- WSReturnModel wsReturnModel = new WSReturnModel();
- wsReturnModel.setTransactionCode(TransactionCode);
- try {
- initJDBC();
- wsReturnModel.setData(jdbcTemplate.queryForList(sql));
- return WSReturnModel.toXml(wsReturnModel);
- } catch (Exception e1) {
- wsReturnModel.setTransactionCode("-30000");
- wsReturnModel.setRespMessage(e1.getMessage());
- return WSReturnModel.toXml(wsReturnModel);
- }
- }
- /**
- * 获取检查报告单的列表
- *
- * @param cardType
- * @param cardNo
- * @param startDate
- * @param endDate
- * @param mobile
- * @param reportType
- * @return
- */
- public String GetReportList(
- String TransactionCode,
- String cardType,
- String cardNo,
- String startDate,
- String endDate,
- String mobile,
- String reportType) {
- WSReturnModel wsReturnModel = new WSReturnModel();
- wsReturnModel.setTransactionCode(TransactionCode);
- try {
- //initJDBC();
- // StringBuffer sb = new StringBuffer("select * from HDSD01_01 where 1=1 ");
- //if (!StringUtils.isEmpty(endDate)) {
- // sb.append(" and HDSD00_05_026 < '" + endDate + "'");
- // }
- //if (!StringUtils.isEmpty(startDate)) {
- // sb.append(" and HDSD00_01_001 > '" + startDate + "'");
- // }
- //wsReturnModel.setData(jdbcTemplate.queryForList(sb.toString()));
- // return WSReturnModel.toXml(wsReturnModel);
- return getFileByPath("C:\\Documents and Settings\\Administrator\\桌面\\data\\GetReportList.xml");
- } catch (Exception e) {
- wsReturnModel.setTransactionCode("-30000");
- wsReturnModel.setRespMessage(e.getMessage());
- return WSReturnModel.toXml(wsReturnModel);
- }
- }
- /**
- * 检查报告单/检验报告单明细
- *
- * @param reportId
- * @param reportType
- * @return
- */
- public String GetReportInfo(
- String TransactionCode,
- String reportId,
- String reportType) {
- WSReturnModel wsReturnModel = new WSReturnModel();
- wsReturnModel.setTransactionCode(TransactionCode);
- try {
- /*
- initJDBC();
- StringBuffer sb = new StringBuffer("select * from HDSD01_01 where 1=1 ");
- if (!StringUtil.isEmpty(reportId)) {
- sb.append(" and HDSD00_05_026 < '" + reportId + "'");
- }
- if (!StringUtil.isEmpty(reportType)) {
- sb.append(" and HDSD00_01_001 > '" + reportType + "'");
- }*/
- // wsReturnModel.setData(jdbcTemplate.queryForList(sb.toString()));
- return getFileByPath("C:\\Documents and Settings\\Administrator\\桌面\\data\\GetReportInfo.xml");
- } catch (Exception e) {
- wsReturnModel.setTransactionCode("-30000");
- wsReturnModel.setRespMessage(e.getMessage());
- return WSReturnModel.toXml(wsReturnModel);
- }
- }
- public String QueryUserInfo(String TransactionCode, String CardType, String CardNo, String Mobile, String PatientId) {
- WSReturnModel wsReturnModel = new WSReturnModel();
- wsReturnModel.setTransactionCode(TransactionCode);
- try {
- /*
- initJDBC();
- StringBuffer sb = new StringBuffer("select * from HDSD01_01 where 1=1 ");
- if (!StringUtil.isEmpty(reportId)) {
- sb.append(" and HDSD00_05_026 < '" + reportId + "'");
- }
- if (!StringUtil.isEmpty(reportType)) {
- sb.append(" and HDSD00_01_001 > '" + reportType + "'");
- }*/
- // wsReturnModel.setData(jdbcTemplate.queryForList(sb.toString()));
- return getFileByPath("C:\\Documents and Settings\\Administrator\\桌面\\data\\QueryUserInfo.xml");
- } catch (Exception e) {
- wsReturnModel.setTransactionCode("-30000");
- wsReturnModel.setRespMessage(e.getMessage());
- return WSReturnModel.toXml(wsReturnModel);
- }
- }
- public static void main(String[] args) throws Exception {
- /*
- JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
- Client client = factory.createClient("http://172.19.103.71:8080/service/sql?wsdl");
- //Client client = factory.createClient("http://localhost:8080/service/sql?wsdl");
- try {
- 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)"); // 按照方法的参数来提供值
- if (result != null && result.length > 0) {
- System.out.println(result[0]); // 通过getUsername来获取对象的username属性
- }
- } catch (Exception e) {
- e.printStackTrace();
- }*/
- System.out.println(getFileByPath("C:\\Users\\Administrator\\Desktop\\getReportInfo.xml"));
- }
- public static String getFileByPath(String path) {
- BufferedReader reader = null;
- FileReader fileReader = null;
- try {
- File cfgFile = ResourceUtils.getFile(path);
- fileReader=new FileReader(cfgFile);
- reader = new BufferedReader(fileReader);
- String line;
- String strContent = "";
- while ((line = reader.readLine()) != null) {
- strContent += line;
- }
- return strContent;
- } catch (Exception e) {
- return "";
- } finally {
- if(reader!=null){
- try {
- reader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(fileReader!=null){
- try {
- fileReader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
|