package com.ann.demo.interfaces.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ann.demo.entity.constant.InterfaceName;
import com.ann.demo.entity.filing.ArchiveDetail;
import com.ann.demo.entity.filing.EMRData;
import com.ann.demo.entity.filing.MessageSubordinate;
import com.ann.demo.entity.filing.dto.MessageDto;
import com.ann.demo.entity.filing.dto.PatientMainDto;
import com.ann.demo.entity.interfaceEntity.*;
import com.ann.demo.interfaces.HomepageDictionary;
import com.ann.demo.primaryEntity.ScanningFile;
import com.ann.demo.repository.CommonTableRepository;
import com.ann.demo.service.*;
import com.ann.demo.utils.FileUtils;
import com.ann.demo.utils.PdfUtils;
import com.ann.demo.utils.WebServiceUtils;
import com.ann.demo.utils.XMLUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jws.WebService;
import java.io.File;
import java.util.Date;
import java.util.Objects;

/**
 * @Author: LeiJiaXin
 * @Date: 2019/6/11 17:01
 */

@WebService(serviceName = "HomepageDictionary", // 与接口中指定的name一致
        targetNamespace = "http://interfaces.demo.ann.com/", // 与接口中的命名空间一致,一般是接口的包名倒
        endpointInterface = "com.ann.demo.interfaces.HomepageDictionary"// 接口地址
)
public class HomepageDictionaryImpl implements HomepageDictionary {

    private static final Logger logger = LoggerFactory.getLogger(HomepageDictionaryImpl.class);

    @Autowired
    private AnalysisService analysisService;

    public String ScanningFile(String xmlStr) {
        String outContent = "失败";
        try {
            boolean flag = false;
            String remark = null;
            MessageDto messageDto = XMLUtils.xpathToBean(xmlStr, EMRData.class, InterfaceName.SCANNING_FILE);
            if (messageDto != null) {
                remark = analysisService.handlePdfFile1(messageDto);
                if(remark == null){
                    flag = true;
                }
            } else {
                remark = "传过来的消息无法解析。。";
            }
            System.out.println(remark);
            outContent = AnalysisService.getReturnResult(flag, remark);
        }catch (Exception e){
            logger.error("出错咯！错误信息为{}，以及错误行数为:{}" ,e,e.getStackTrace()[0]);
        }
        return outContent;
    }

}
