package com.docus.server.collect.user;

import com.docus.core.util.XmlUtil;
import com.docus.server.collect.mq.user.AbstractUserMqCollectService;
import com.docus.server.sys.common.pojo.dto.UserDTO;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;

@Service
public class JmsIbmMqUserCollectServiceImpl extends AbstractUserMqCollectService {
    /**
     * 监听注解订阅，自己编写
     *
     * @param message 科室信息
     */
    //@JmsIbmListener(destination = "TJ_createPractitioner")
    @Override
    public void addUser(String message) {
        super.addUser(message);
    }

    /**
     * 监听注解订阅，自己编写
     *
     * @param message 科室信息
     */
    //@JmsIbmListener(destination = "TJ_updatePractitioner")
    @Override
    public void updateUser(String message) {
        super.updateUser(message);
    }

    /**
     * 解析新增的消息, 下面是个例子
     *
     * @param xml
     * @return
     */
    @Override
    public UserDTO parseAddUserXml(String xml) {
        XmlUtil xmlParseUtil = XmlUtil.of(xml);
        Node employeeCodeNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/id/item/@extension");
        Node employeeNameNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/name/item[@use='OR']/part/@value");
        Node deptCodeNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/asAffiliate/affiliatedPrincipalOrganization/id/item/@extension");
        Node positionNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/relatedTo/assignedEntity/relatedTo/assignedEntity/code[@codeSystem='2.16.156.10011.0.9.2.3.2.122']/displayName/@value");
        Node authorIdNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
        Node authorNameNode = xmlParseUtil.getNode("/PRPM_IN301010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");

        UserDTO userDto = new UserDTO();
        userDto.setDeptId(deptCodeNode.getNodeValue());
        userDto.setUserName(employeeCodeNode.getNodeValue());
        userDto.setName(employeeNameNode.getNodeValue());
        userDto.setPosition(positionNode.getNodeValue());
        userDto.setAuthorId(authorIdNode.getNodeValue());
        userDto.setAuthorName(authorNameNode.getNodeValue());
        userDto.setRoleId(0L);
        return userDto;
    }

    /**
     * 解析更新的消息, 下面是个例子
     *
     * @param xml
     * @return
     */
    @Override
    public UserDTO parseUpdateUserXml(String xml) {
        XmlUtil xmlParseUtil = XmlUtil.of(xml);
        Node employeeCodeNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/id/item/@extension");
        Node employeeNameNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/name/item[@use='OR']/part/@value");
        Node deptCodeNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/healthCarePrincipalPerson/asAffiliate/affiliatedPrincipalOrganization/id/item/@extension");
        Node positionNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/subject1/healthCareProvider/relatedTo/assignedEntity/relatedTo/assignedEntity/code[@codeSystem='2.16.156.10011.0.9.2.3.2.122']/displayName/@value");
        Node authorIdNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
        Node authorNameNode = xmlParseUtil.getNode("/PRPM_IN303010UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");

        UserDTO userDto = new UserDTO();
        userDto.setDeptId(deptCodeNode.getNodeValue());
        userDto.setUserName(employeeCodeNode.getNodeValue());
        userDto.setName(employeeNameNode.getNodeValue());
        userDto.setPosition(positionNode.getNodeValue());
        userDto.setAuthorId(authorIdNode.getNodeValue());
        userDto.setAuthorName(authorNameNode.getNodeValue());
        userDto.setRoleId(0L);
        return userDto;
    }


}
