Ver código fonte

补充建章采集的东西

1 3 semanas atrás
pai
commit
b6c00b5c8a
4 arquivos alterados com 74 adições e 4 exclusões
  1. 30 0
      common/file.go
  2. 29 0
      common/period.go
  3. 10 0
      common/rod_utils.go
  4. 5 4
      common/variable/const.go

+ 30 - 0
common/file.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"github.com/go-rod/rod/lib/utils"
 	"os"
+	"strings"
 )
 
 // GetCollectPDFPath 生成一个采集用的pdf路径
@@ -45,3 +46,32 @@ func PDFtoStrArrayPython(path string) ([][]string, error) {
 	json.Unmarshal(bys, &code)
 	return code, nil
 }
+
+// UploadPdfToStrArray java PDF转数组
+func UploadPdfToStrArray(path string) ([]string, error) {
+	f := 0
+begin:
+	url := "http://47.104.75.113:8080/api/uploadPdfToText" //灵信服务器
+	files := map[string]string{
+		"file": path,
+	}
+	resp, err := PostFile(url, files, map[string]string{})
+	arr := []string{}
+	if err != nil {
+		if f < 3 {
+			f++
+			utils.Sleep(10)
+			goto begin
+		}
+		return arr, err
+	}
+	type resut struct {
+		Text string `json:"text"`
+	}
+	var Result resut
+	if err := json.Unmarshal(resp, &Result); err != nil {
+		return arr, err
+	}
+	arr = strings.Split(Result.Text, "\n")
+	return arr, nil
+}

+ 29 - 0
common/period.go

@@ -263,3 +263,32 @@ func LastJiDu(startAccountPeriod string) string {
 	}
 	return newPeriod
 }
+
+// 根据本账期查询上个账期 例如 201812 -> 2018-11
+func LastPeriod1(startAccountPeriod string) string {
+	if len(startAccountPeriod) < 6 {
+		return ""
+	}
+	qian4 := startAccountPeriod[0 : len(startAccountPeriod)-2]
+	hou2 := startAccountPeriod[4 : len(startAccountPeriod)-0]
+	newPeriod := ""
+	if StrToInt(hou2) == 1 {
+		newPeriod = IntToStr(StrToInt(qian4)-1) + "12"
+	} else {
+		newPeriod = IntToStr(StrToInt(startAccountPeriod) - 1)
+	}
+	return newPeriod[:4] + "-" + newPeriod[4:]
+}
+
+// GetLastBeginAndEndTime 获取上个账期的起止时间
+func GetLastBeginAndEndTime(period string) (string, string) {
+	lastP := getCurrentPeriod(period)
+	return GetBeginAndEndTime(lastP)
+}
+
+// 获取上月
+func getCurrentPeriod(period string) string {
+	parse, _ := time.Parse(`200601`, period)
+	period = parse.AddDate(0, -1, 0).Format("200601") // 获取上月
+	return period
+}

+ 10 - 0
common/rod_utils.go

@@ -340,3 +340,13 @@ func WaitForPageLoad(page *rod.Page, timeoutDuration time.Duration, selector ...
 	})
 	utils.Sleep(3)
 }
+
+func WaitHasX(page *rod.Page, xpath string) (x bool) {
+	for i := 0; i < 5; i++ {
+		x, _, _ = HasX(page, xpath)
+		if !x {
+			utils.Sleep(1)
+		}
+	}
+	return x
+}

+ 5 - 4
common/variable/const.go

@@ -3,10 +3,11 @@ package variable
 const TaxTaskURL string = "https://task.listensoft.net"          //获取任务的URL
 const SessionKeepURL string = "https://keepalive.listensoft.net" //session会话保持服务器
 
-type LXContextVar string         // ctx传递存储的信息KEY
-type Environment string          //环境变量
-type Kjze string                 //会计准则
-const UUID LXContextVar = "uuid" //标志
+type LXContextVar string               // ctx传递存储的信息KEY
+const ComInfo LXContextVar = "comInfo" //企业基本信息
+type Environment string                //环境变量
+type Kjze string                       //会计准则
+const UUID LXContextVar = "uuid"       //标志
 func (k Kjze) Check() bool {
 	if k == KjXqy2013 || k == KjYbqyWzx || k == KjQykjzd || k == KjYbqyYzx || k == KjMbf || k == Nyhzs {
 		return true