package com.docus.server.collection.webservice.impl;

import com.docus.server.collection.dto.DeptDto;
import com.docus.server.collection.dto.DeptModifyParam;
import com.docus.server.collection.dto.UserDto;
import com.docus.server.collection.dto.UserModifyParam;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.junit.Test;

public class DeptServerImplTest {
    String xml = "<PRVS_IN000002UV01 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\">\n" +
            "\t<!--消息唯一ID-->\n" +
            "\t<id extension=\"a10f1ad0-6f12-41b6-95f2-a629490774cf\"/>\n" +
            "\t<!--creationTime-消息创建时间-->\n" +
            "\t<creationTime value=\"20221115164552\"/>\n" +
            "\t<!--interactionId-消息的服务标识-->\n" +
            "\t<interactionId root=\"2.16.840.1.113883.1.6\" extension=\"PRVS_IN000002UV01\"/>\n" +
            "\t<!--processingCode-处理代码。标识此消息是否是产品、训练、调试系统的一部分。D：调试；P：产\n" +
            "品；T：训练-->\n" +
            "\t<processingCode code=\"P\"/>\n" +
            "\t<!--processingModeCode-处理模型代码。定义此消息是一个文档处理还是一个初始装载的一部分。A：\n" +
            "存档；I：初始装载；R：从存档中恢复；T：当前处理，间隔传递。-->\n" +
            "\t<processingModeCode/>\n" +
            "\t<!--acceptAckCode-接收确认类型 AL：总是确认；NE：从不确认；ER：仅在错误/或拒绝时确认；SU：\n" +
            "仅在成功完成时确认。-->\n" +
            "\t<acceptAckCode code=\"AL\"/>\n" +
            "\t<receiver typeCode=\"RCV\">\n" +
            "\t\t<device classCode=\"DEV\" determinerCode=\"INSTANCE\">\n" +
            "\t\t\t<id>\n" +
            "\t\t\t\t<!-- 指定接收方，用于 Orion 通讯点路由 -->\n" +
            "\t\t\t\t<item root=\"2.16.156.10011.0.1.1\" extension=\"MDM\"/>\n" +
            "\t\t\t</id>\n" +
            "\t\t</device>\n" +
            "\t</receiver>\n" +
            "\t<sender typeCode=\"SND\">\n" +
            "\t\t<device classCode=\"DEV\" determinerCode=\"INSTANCE\">\n" +
            "\t\t\t<id>\n" +
            "\t\t\t\t<!-- 指定发送方，用于 Orion 通讯点路由 -->\n" +
            "\t\t\t\t<item root=\"2.16.156.10011.0.1.2\" extension=\"HIS-001\"/>\n" +
            "\t\t\t</id>\n" +
            "\t\t</device>\n" +
            "\t</sender>\n" +
            "\t<controlActProcess classCode=\"CACT\" moodCode=\"EVN\">\n" +
            "\t\t<code code=\"ValueSetUpdate\">\n" +
            "\t\t\t<displayName value=\"字典更新\"/>\n" +
            "\t\t</code>\n" +
            "\t\t<subject typeCode=\"SUBJ\">\n" +
            "\t\t\t<registrationRequest classCode=\"REG\" moodCode=\"RQO\">\n" +
            "\t\t\t\t<statusCode/>\n" +
            "\t\t\t\t<!--值集注册，subject1为1..1-->\n" +
            "\t\t\t\t<subject1 typeCode=\"SBJ\">\n" +
            "\t\t\t\t\t<valueSet>\n" +
            "\t\t\t\t\t\t<!--值集标识符 STANDARD_CODE-->\n" +
            "\t\t\t\t\t\t<id extension=\"HIP833\"/>\n" +
            "\t\t\t\t\t\t<!--值集描述 COLLECTION_NAME + COLLECTION_VERSION-->\n" +
            "\t\t\t\t\t\t<desc value=\"人员his科室字典\"/>\n" +
            "\t\t\t\t\t\t<!--值集状态代码-->\n" +
            "\t\t\t\t\t\t<statusCode code=\"1\"/>\n" +
            "\t\t\t\t\t\t<!--字典的副本号 RELEASE_TAG-->\n" +
            "\t\t\t\t\t\t<version code=\"1.0\">\n" +
            "\t\t\t\t\t\t\t<originalText value=\"\"/>\n" +
            "\t\t\t\t\t\t</version>\n" +
            "\t\t\t\t\t\t<!-- 字典具体的某一行数据，operateType有三种值：C 代表新增、U 代表修改、D 代表删除-->\n" +
            "\t\t\t\t\t\t<valueSetItems operateType=\"CU\">\n" +
            "\t\t\t\t\t\t\t<!--科室编码-->\n" +
            "\t\t\t\t\t\t\t<DEPT_CODE value=\"M010615\"/>\n" +
            "\t\t\t\t\t\t\t<!--科室名称-->\n" +
            "\t\t\t\t\t\t\t<DEPT_NAME value=\"卵巢早衰专科\"/>\n" +
            "\t\t\t\t\t\t\t<!--科室类型（门诊住院）-->\n" +
            "\t\t\t\t\t\t\t<DEPT_TYPE value=\"\"/>\n" +
            "\t\t\t\t\t\t\t<!--拼音简码-->\n" +
            "\t\t\t\t\t\t\t<SPELL_CODE value=\"LCZSZK\"/>\n" +
            "\t\t\t\t\t\t\t<!--五笔简码-->\n" +
            "\t\t\t\t\t\t\t<WB_CODE value=\"QVJYFT\"/>\n" +
            "\t\t\t\t\t\t\t<!--科室地址-->\n" +
            "\t\t\t\t\t\t\t<DEPT_ADDRESS value=\"1号楼6楼C区\"/>\n" +
            "\t\t\t\t\t\t\t<!--备注-->\n" +
            "\t\t\t\t\t\t\t<REMARKS value=\"\"/>\n" +
            "\t\t\t\t\t\t\t<!--科室角色状态代码-->\n" +
            "\t\t\t\t\t\t\t<STATUS_CODE value=\"1\"/>\n" +
            "\t\t\t\t\t\t\t<!--机构代码-->\n" +
            "\t\t\t\t\t\t\t<ORG_CODE value=\"4560886379\"/>\n" +
            "\t\t\t\t\t\t\t<!--机构名称-->\n" +
            "\t\t\t\t\t\t\t<ORG_NAME value=\"南方医科大学顺德医院\"/>\n" +
            "\t\t\t\t\t\t</valueSetItems>\n" +
            "\t\t\t\t\t</valueSet>\n" +
            "\t\t\t\t</subject1>\n" +
            "\t\t\t\t<!-- 谁做了本次操作-->\n" +
            "\t\t\t\t<author typeCode=\"AUT\">\n" +
            "\t\t\t\t\t<assignedEntity classCode=\"ASSIGNED\">\n" +
            "\t\t\t\t\t\t<id>\n" +
            "\t\t\t\t\t\t\t<item root=\"2.16.156.10011.1.4\" extension=\"操作人ID\"/>\n" +
            "\t\t\t\t\t\t</id>\n" +
            "\t\t\t\t\t\t<assignedPerson classCode=\"PSN\" determinerCode=\"INSTANCE\">\n" +
            "\t\t\t\t\t\t\t<name xsi:type=\"DSET_EN\">\n" +
            "\t\t\t\t\t\t\t\t<item>\n" +
            "\t\t\t\t\t\t\t\t\t<part value=\"操作人名称\"/>\n" +
            "\t\t\t\t\t\t\t\t</item>\n" +
            "\t\t\t\t\t\t\t</name>\n" +
            "\t\t\t\t\t\t</assignedPerson>\n" +
            "\t\t\t\t\t</assignedEntity>\n" +
            "\t\t\t\t</author>\n" +
            "\t\t\t</registrationRequest>\n" +
            "\t\t</subject>\n" +
            "\t</controlActProcess>\n" +
            "</PRVS_IN000002UV01>\n";
    @Test
    public void parseDeptDtoTest() {
        DeptServerImpl deptServer = new DeptServerImpl();
        DeptDto deptDto = deptServer.strToDeptDto(xml);
        DeptModifyParam addParam = deptDto.transDeptAddParam();

        System.out.println(deptDto);
        System.out.println(addParam);
        assert deptDto.getDeptName().equals(addParam.getDeptName());
        assert deptDto.getAuthorId().equals(addParam.getAuthorId());
        assert deptDto.getAuthorName().equals(addParam.getAuthorName());
        assert deptDto.getDeptCode().equals(addParam.getDeptCode());
    }

    @Test
    public void modifyWebserviceTest() throws Exception{
//        JaxWsDynamicClientFactory jaxWsDynamicClientFactory = JaxWsDynamicClientFactory.newInstance();
//        Client client = jaxWsDynamicClientFactory.createClient("http://localhost:9111/webservice/api/dept?wsdl");
//        Object[] invoke = client.invoke("deptModify", xml);
//        System.out.println(invoke[0].toString());
    }
}
