package main

import (
	"bytes"
	"fmt"
	"io"
	qu "qfw/util"
	sp "spiderutil"
)

//调用附件解析ocr测试
func mainT1() {
	attachText := map[string]interface{}{}
	url := "https://e-bidding.zzcycn.com/bidprocurement/datacenter-cebpubserver/cebpubserver/dataCeboubServerCommonController/openFileById?fileType=2&id=c66b56202bfe4420abc0208b7c3bb9f3"
	contentType, ret := Download(url) //下载
	fmt.Println(contentType)
	fileType := "pdf" //从url或者text提取的附件类型
	fileName := "公告.pdf"
	fid := sp.GetHashKey(ret) + sp.TypeByExt(fileName)
	fmt.Println(fid)
	bs := bytes.NewReader(ret)
	Ok, _ := sp.OssPutObject(fid, io.MultiReader(bs)) //附件上传
	if Ok {                                           //上传成功，解析附件
		resp := GetFileText(fileName, fid, fileType, ret)
		fmt.Println(resp)
		if resp != nil {
			tmap := map[string]interface{}{}
			for i, r := range resp.Result {
				rmap := map[string]interface{}{
					"file_name":  r.FileName,
					"attach_url": r.TextUrl,
					"state":      r.ErrorState,
				}
				tmap[fmt.Sprint(i)] = rmap
			}
			if len(tmap) > 0 {
				attachText[fmt.Sprint(1)] = tmap
			}
		}
	}
	qu.Debug(attachText)
}

//流程测试
func mainT() {
	GetDataAndDownload("6556f82c27f8b3af542c05f1", "6556f82c27f8b3af542c05f2")
}
