1 2 weeks ago
parent
commit
59b50f2654
6 changed files with 109 additions and 0 deletions
  1. 5 0
      common/converter.go
  2. 26 0
      common/file.go
  3. 14 0
      common/period.go
  4. 25 0
      common/rod_utils.go
  5. 38 0
      common/utils.go
  6. 1 0
      common/variable/const.go

+ 5 - 0
common/converter.go

@@ -318,3 +318,8 @@ func FloatToStr4(f float64, len int) string {
 	// 100.12
 	return strconv.FormatFloat(f, 'f', len, 64)
 }
+
+// string to Float
+func AmountFormat(str string) float64 {
+	return StrToFloatAll(strings.TrimSpace(strings.ReplaceAll(str, ",", "")))
+}

+ 26 - 0
common/file.go

@@ -3,11 +3,13 @@ package common
 import (
 	"encoding/json"
 	"fmt"
+	"git.listensoft.net/tool/jspkit/logger"
 	"github.com/go-rod/rod/lib/utils"
 	"github.com/tidwall/gjson"
 	"os"
 	"path/filepath"
 	"strings"
+	"time"
 )
 
 // GetCollectPDFPath 生成一个采集用的pdf路径
@@ -119,3 +121,27 @@ func GetCollectZipPath(district, taxNo, taxTape string) (string, error) {
 	path = path + taxNo + "_" + taxTape + ".zip"
 	return path, err
 }
+
+// 保存时长文件  地区 任务 开始/结束
+func SaveDurationToFile(area string, task string, msg string) {
+	path := "./data/duration/"
+	if !PathExists(path) {
+		os.MkdirAll(path, os.ModePerm)
+	}
+	path = path + "file.txt"
+	data := area + "----" + task + "----" + time.Now().Format("2006-01-02 15:04:05") + "---用时---" + msg + "秒"
+
+	// 创建或打开文件,文件名为test.txt,使用读写权限打开
+	file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+	if err != nil {
+		logger.Info("打开文件失败")
+	}
+	defer file.Close()
+
+	// 写入数据
+	//writeData := []byte(data)
+	_, err = file.WriteString("\r" + data)
+	if err != nil {
+		logger.Info("写入文件失败")
+	}
+}

+ 14 - 0
common/period.go

@@ -302,6 +302,9 @@ func GetFirstAndLastDayOfPeriod(period string) (string, string) {
 	return firstDay.Format("2006-01-02"), lastDay.Format("2006-01-02")
 }
 
+// RFC3339     = "2006-01-02T15:04:05Z07:00"
+const TimeFormat = "2006-01-02 15:04:05"
+
 // DateFormatter 将YYYYMMDD格式改为YYYY-MM-DD格式
 func DateFormatter(date string) string {
 	if len(date) != 8 {
@@ -440,3 +443,14 @@ func GetCurrentDate1() string {
 	period := firstOfMonth.AddDate(0, 0, 0).Format("2006-01") // 当前日期
 	return period
 }
+
+// 获取本月开始和结束的时间
+func GetBeginAndEndTime1(period string) (string, string) {
+	loc, _ := time.LoadLocation("Local")
+	the_time, _ := time.ParseInLocation("200601", period, loc)
+	year, month, _ := the_time.Date()
+	thisMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
+	start := thisMonth.AddDate(0, 0, 0).Format("2006-1-2")
+	end := thisMonth.AddDate(0, 1, -1).Format("2006-1-2")
+	return start, end
+}

+ 25 - 0
common/rod_utils.go

@@ -650,3 +650,28 @@ func WaitHasX15(page *rod.Page, xpath string) (x bool) {
 	}
 	return x
 }
+
+// 这个方法存在bug 如果新页面没加载完,爬出异常了,就会存在新页面没关闭的情况
+func WaitTimeOutPage(f func() *rod.Page, timeout time.Duration) *rod.Page {
+	resultChan := make(chan *rod.Page, 1)
+	go func() {
+		page := f()
+		resultChan <- page
+	}()
+	select {
+	case p := <-resultChan:
+		return p
+	case <-time.After(timeout):
+		panic(taxerr.NewWebStuckTitle(ComInfo.Cscsts))
+	}
+}
+
+func MustHasXV10(page *rod.Page, xpath string) bool {
+	for _, element := range MustElementsX10(page, xpath) {
+		visible, _ := element.Visible()
+		if visible {
+			return true
+		}
+	}
+	return false
+}

+ 38 - 0
common/utils.go

@@ -475,3 +475,41 @@ func TimeFormatM(str string, Type int) string {
 func DelSpace(str string) string {
 	return strings.Replace(str, " ", "", -1)
 }
+
+// 登录异常统一提示
+func LoginErr() *taxerr.SystemErr {
+	return taxerr.NewSystemV3("登录出现异常", "系统将于30分钟后重试(可在\"通用设置\"关闭)")
+}
+
+func GetMobileOnline(mobile string) bool {
+	type getAppHeartbeatSmsRes struct {
+		Data struct {
+			List []struct {
+				ID        int       `json:"ID"`
+				CreatedAt time.Time `json:"CreatedAt"`
+				UpdatedAt time.Time `json:"UpdatedAt"`
+				Mobile    string    `json:"Mobile"`
+				Heartbeat time.Time `json:"Heartbeat"`
+				Status    string    `json:"status"`
+			} `json:"list"`
+			Total int `json:"total"`
+		} `json:"data"`
+		ErrNo int    `json:"errNo"`
+		Msg   string `json:"msg"`
+	}
+
+	resp, err := http.Post(`https://public.listensoft.net/api/getAppHeartbeatSms`, "application/json", bytes.NewBufferString(`{"mobile":"`+mobile+`"}`))
+	if err != nil {
+		return false
+	}
+	all, err := io.ReadAll(resp.Body)
+	logger.Info("getAppHeartbeatSms:", string(all))
+	res := getAppHeartbeatSmsRes{}
+	_ = json.Unmarshal(all, &res)
+	for _, m := range res.Data.List {
+		if m.Mobile == mobile && m.Status == "ok" {
+			return true
+		}
+	}
+	return false
+}

+ 1 - 0
common/variable/const.go

@@ -8,6 +8,7 @@ const ComInfo LXContextVar = "comInfo" //企业基本信息
 type Environment string                //环境变量
 type Kjze string                       //会计准则
 const UUID LXContextVar = "uuid"       //标志
+const BsTask LXContextVar = "bsTask"   //办税任务
 func (k Kjze) Check() bool {
 	if k == KjXqy2013 || k == KjYbqyWzx || k == KjQykjzd || k == KjYbqyYzx || k == KjMbf || k == Nyhzs {
 		return true