/**
 * Copyright (C), 2015-2019
 * Author:   HJL
 * Date:     2019/8/1 16:07
 * Description:
 */
package com.emr.util;

import com.emr.webservice.MedicalRecordShowBackContent.*;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import org.apache.pdfbox.multipdf.PDFMergerUtility;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class test {

    private static String[] getFiles(String folder) throws IOException {
        File _folder = new File(folder);
        String[] filesInFolder;

        if (_folder.isDirectory()) {
            filesInFolder = _folder.list();
            return filesInFolder;
        } else {
            throw new IOException("Path is not a directory");
        }
    }

    private static void pdfToPdf(String folder,String fileName) throws Exception {
        PDFMergerUtility mergePdf = new PDFMergerUtility();
        String[] filesInFolder = getFiles(folder);
        for (int i = 0; i < filesInFolder.length; i++){
            mergePdf.addSource(folder + File.separator + filesInFolder[i]);
            //System.out.println(filesInFolder[i]);
        }
        mergePdf.setDestinationFileName(folder + File.separator + fileName);
       // System.out.println(folder);
        mergePdf.mergeDocuments();
        //System.out.print("done");
    }

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
      // String folder = "D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\pdfFiles";
       // String fileName = "mergedTest.pdf";
        //pdfToPdf(folder, fileName);

        //String str = "D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\4\\a.jpg";
        //获得第一个点的位置
       // int index = str.indexOf("\\static");
        //String result = str.substring(0,index+1);
        //输出结果
        ///System.out.println(str.substring(index, str.length()));
        // JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        // Client client = dcf.createClient(HomepageDictionary);
        // Object[] objects = client.invoke("getInfosByUserId", token, "emr_medical_record");
        // System.out.println(client);
//        try {
//            String endpoint = "http://120.27.212.36:9999/filing/services/HomepageDictionary?wsdl";
//            //String endpoint = "http://localhost:8080/ca3/services/caSynrochnized?wsdl";
//            //直接引用远程的wsdl文件
//            //以下都是套路
//            Service service = new Service();
//            Call call = (Call) service.createCall();
//            call.setTargetEndpointAddress(endpoint);
//            call.setOperationName(new QName("http://interfaces.ann.com/", "CheckData"));
//
//            //call.setOperationName("CheckData");//WSDL里面描述的接口名称
//            call.addParameter("masterId", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN);//接口的参数
//            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
//            String temp = "02e4ba493dc643c9926926662327995e";
//            String result = (String) call.invoke(new Object[]{temp});
//            //给方法传递参数，并且调用方法
//
//            System.out.println("result is " + result);
//
//        } catch (Exception e) {
//            System.err.println(e.toString());
//
//        }


        /*String method = "CheckData";
        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
        //Client client = factory.createClient("http://120.27.212.36:9999/filing/services/HomepageDictionary?wsdl");
        Client client = factory.createClient("http://127.0.0.1:8080/WholeCheckInterface/services/HomepageDictionary?wsdl");
//        Endpoint endpoint2 = client.getEndpoint();
//        QName opName = new QName(endpoint2.getService().getName().getNamespaceURI(), method);
//        BindingInfo bindingInfo = endpoint2.getEndpointInfo().getBinding();
//        if (bindingInfo.getOperation(opName) == null) {
//            for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
//                if (method.equals(operationInfo.getName().getLocalPart())) {
//                    opName = operationInfo.getName();
//                    break;
//                }
//            }
//        }
        Object[] res = null;
        res = client.invoke("CheckData","3f3d18cf-6f75-4367-9ada-3684e176c102");
        String xml = (String) res[0];
        System.err.println("@@@@@@@@@@@@@@@@@" + xml);*/


//        String endpoint = "http://10.6.1.152:8037/SignWebService.asmx?WSDL";
//        String method = "MedicalRecordRepair";

        String mrFILECALLBACKRECORDxml="";//入参1
        String mrFILEINDEXCALLBACKxml="";//入参2

        /*MR_FILE_CALLBACK_RECORDxml inputParam1 = new MR_FILE_CALLBACK_RECORDxml();
        inputParam1.setPATIENT_ID("2");
        inputParam1.setVISIT_ID("2");
        inputParam1.setFILE_UNIQUE_ID("1");
        inputParam1.setAPPLY_DATE_TIME("2014-04-15T10:51:39");
        inputParam1.setAPPLY_TIME_LIMIT("2014-04-15T10:51:39");
        inputParam1.setAPPLY_REASON("1");
        inputParam1.setEXPIRY_TIME("2014-04-15T10:51:39");

        MR_FILE_INDEX_CALLBACKxml inputParam2 = new MR_FILE_INDEX_CALLBACKxml();
        inputParam2.setPATIENT_ID("2");
        inputParam2.setVISIT_ID("2");
        inputParam2.setAPPLY_DATE_TIME("2014-04-15T10:51:39");
        inputParam2.setAPPLY_TIME_LIMIT("2014-04-15T10:51:39");
        inputParam2.setAPPLY_USER_NAME("1");
        inputParam2.setAPPLY_DEPT_CODE("1");
        inputParam2.setSTATUS("1");
        inputParam2.setAPPROVE_USER_ID("1");
        inputParam2.setAPPROVE_USER_NAME("1");
        inputParam2.setAPPROVE_DEPT_CODE("1");
        inputParam2.setAPPROVE_DATE_TIME("2014-04-15T10:51:39");
        inputParam2.setAPPLY_REASON("1");
        inputParam2.setCLINIC_TYPE("0");
        inputParam2.setOPERATOR_TYPE("0");
        inputParam2.setLIMIT_DATE("2014-04-15T10:51:39");

        mrFILECALLBACKRECORDxml = XMLUtil.convertToXml(inputParam1);
        mrFILEINDEXCALLBACKxml = XMLUtil.convertToXml(inputParam2);

        System.out.println(mrFILECALLBACKRECORDxml);
        System.out.println(mrFILEINDEXCALLBACKxml);

//        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
//        Client client = factory.createClient(endpoint);
        SignWebService signWebService = new SignWebService();
        SignWebServiceSoap signWebServiceSoap = signWebService.getSignWebServiceSoap();
        String str = signWebServiceSoap.medicalRecordRepair(mrFILECALLBACKRECORDxml, mrFILEINDEXCALLBACKxml);
        System.out.println(str);*/



        /*String file = "d:/1.pdf";
        String file2 = "d:/0.pdf";
        PdfReader pdfReader = new PdfReader(file);
//        PdfStamper pt = new PdfStamper(pdfReader,new FileOutputStream(file2));
//        pt.setRotateContents(false);
//        Rectangle p = pt.getOverContent(1).getPdfDocument().getPageSize();
        Rectangle p2 =pdfReader.getPageSizeWithRotation(1);
//        pt.close();
        System.out.println(p2);*/
    }

    public void test() {
    }
}


