package com.docus.server.collect.basic.ws;

import com.docus.core.util.DateUtil;
import com.docus.core.util.Func;
import com.docus.log.context.TrackContext;
import com.docus.server.collect.basic.ws.impl.BasicServerImpl;
import com.docus.server.collect.IWsResult;
import com.docus.server.collect.web.process.VisitorProcessor;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

/**
 * webservice被动请求响应类型，需要和controller返回类型保持一致
 *
 * @see BasicServerImpl#setTBasic(String)
 * @see VisitorProcessor#doProcess(TrackContext)
 */
@Component("wsBasicResultImpl")
public class WsBasicResultImpl implements IWsResult {


    @Override
    public String ok(Map<String, Object> params) {
        return "hello";
    }

    @Override
    public String fail(Map<String, Object> params) {
        String createTime = Func.format(new Date(), DateUtil.PATTERN_DATETIME_MINI);
        return "<MCCI_IN000002UV01 xmlns=\"urn:hl7-org:v3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ITSVersion=\"XML_1.0\" xsi:schemaLocation=\"urn:hl7-org:v3  file:///E:/hl7/HL7/v3ballot_fullsite_2011MAY/v3ballot/html/processable/multicacheschemas/MCCI_IN000002UV01.xsd\">  \n" +
            "  <id extension=\"" + Func.randomUUID() + "\"/>  \n" +
            "  <creationTime value=\"" + createTime + "\"/>  \n" +
            "  <interactionId root=\"2.16.840.1.113883.1.6\" extension=\"MCCI_IN000002UV01\" displayable=\"true\"/>  \n" +
            "  <processingCode code=\"P\"/>  \n" +
            "  <processingModeCode/>  \n" +
            "  <acceptAckCode code=\"AL\"/>  \n" +
            "  <receiver typeCode=\"RCV\"> \n" +
            "    <device classCode=\"DEV\" determinerCode=\"INSTANCE\"> \n" +
            "      <id> \n" +
            "        <item extension=\"" + params.get("receive") + "\"/> \n" +
            "      </id> \n" +
            "    </device> \n" +
            "  </receiver>  \n" +
            "  <sender typeCode=\"SND\"> \n" +
            "    <device classCode=\"DEV\" determinerCode=\"INSTANCE\"> \n" +
            "      <id> \n" +
            "        <item extension=\"" + params.get("send") + "\"/> \n" +
            "      </id> \n" +
            "    </device> \n" +
            "  </sender>  \n" +
            "  <acknowledgement typeCode=\"AE\"> \n" +
            "    <!--请求消息ID-->  \n" +
            "    <targetMessage> \n" +
            "      <id extension=\"" + params.get("serialId") + "\"/> \n" +
            "    </targetMessage>  \n" +
            "    <acknowledgementDetail> \n" +
            "      <text value=\"" + params.get("msg") + "\"/> \n" +
            "    </acknowledgementDetail> \n" +
            "  </acknowledgement> \n" +
            "</MCCI_IN000002UV01>\n";
    }
}
