package com.docus.server.collect.dept.http;

import com.docus.server.sys.common.pojo.dto.DeptDTO;
import com.docus.server.collect.IConverter;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component("httpDeptConverter")
public class HttpDeptConverter implements IConverter {

    @Override
    public DeptDTO convert(String message, String group) {
        //TODO： 根据协议进行解析。
//        XmlUtil xmlParseUtil = XmlUtil.of(message);
//        Node msgIdNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/id/@extension");
//        Node receiverNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/receiver/device/id/item/@extension");
//        Node operateTypeNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/subject1/valueSet/valueSetItems/@operateType");
//        Node deptCodeNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/subject1/valueSet/valueSetItems/DEPT_CODE/@value");
//        Node deptNameNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/subject1/valueSet/valueSetItems/DEPT_NAME/@value");
//        Node authorIdNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/id/item/@extension");
//        Node authorNameNode = xmlParseUtil.getNode("/PRVS_IN000002UV01/controlActProcess/subject/registrationRequest/author/assignedEntity/assignedPerson/name/item/part/@value");
//
//        DeptDTO deptDto = new DeptDTO();
//        deptDto.setMessageId(msgIdNode.getNodeValue());
//        deptDto.setReceiver(receiverNode.getNodeValue());
//        deptDto.setOperateType(operateTypeNode.getNodeValue());
//        deptDto.setDeptCode(deptCodeNode.getNodeValue());
//        deptDto.setDeptName(deptNameNode.getNodeValue());
//        deptDto.setAuthorId(authorIdNode.getNodeValue());
//        deptDto.setAuthorName(authorNameNode.getNodeValue());
//        deptDto.setSource(message);//原始xml报文
//
//        deptDto.setParams(ParamsUtils.addParam("msg", "操作成功！")
//            .addParam("msgId", deptDto.getMessageId())
//            .addParam("receiver", deptDto.getReceiver())
//            .param());


        DeptDTO deptDto = new DeptDTO();
        deptDto.setMessageId(UUID.randomUUID().toString());
        deptDto.setReceiver("1");
        deptDto.setOperateType("2");
        deptDto.setDeptCode("3");
        deptDto.setDeptName("4");
        deptDto.setAuthorId("5");
        deptDto.setAuthorName("6");
        deptDto.setSource(message);//原始xml报文

        return deptDto;
    }
}
