package com.engine.htsc.langchaoPDF.service.impl;

import com.engine.core.impl.Service;
import com.engine.htsc.langchaoPDF.service.UploadFileService;
import weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.htsc.cus.webservices.FileInfoEntity;
import weaver.interfaces.htsc.cus.webservices.ImageServiceSoap;
import weaver.interfaces.htsc.cus.webservices.ImageServiceSoapProxy;
import weaver.interfaces.htsc.cus.webservices.UploadfileEntity;

public class UploadFileServiceImpl extends Service implements UploadFileService {
    @Override
    public String uploadFile(String billID, byte[] byteArr, String fileType, String userCode, String fileName) {
        try {
            JAVATools.SetCmdwritelog("浪潮OCR识别上传接口 入参 : billID={} " + billID +
                    " fileType={} " + fileType +
                    " userCode={} " + userCode +
                    " fileName={} " + fileName);
            String sendImageUrl = Util.null2String(new PropBean().getPropName("sendImageUrl"));
            String fileTypeID = Util.null2String(new PropBean().getPropName("cft.image.type.png"));
            ImageServiceSoapProxy issp = new ImageServiceSoapProxy(sendImageUrl);
            ImageServiceSoap service = issp.getImageServiceSoap();

            UploadfileEntity uploadfileEntityr = new UploadfileEntity();
            uploadfileEntityr.setBillID(billID);
            FileInfoEntity[] fileInfoEntityArr = new FileInfoEntity[1];
            FileInfoEntity fileInfo = new FileInfoEntity();
            fileInfo.setContent(byteArr);
            fileInfo.setFileName(fileName);
            fileInfo.setFileTypeID(fileTypeID);
            fileInfoEntityArr[0] = fileInfo;
            uploadfileEntityr.setFileInfoEntityArr(fileInfoEntityArr);
            uploadfileEntityr.setFileType(fileType);
            uploadfileEntityr.setUserCode(userCode);
            String result = service.sendImageOnPC(uploadfileEntityr);
            JAVATools.SetCmdwritelog("浪潮OCR识别上传接口,出参：{}",result);
            return result;
        }catch (Exception e) {
            JAVATools.SetCmdwritelog("浪潮OCR识别上传接口出现异常：",e.getMessage());
            e.printStackTrace();

            return "浪潮OCR识别上传接口 上传失败";
        }

    }
}
