Selaa lähdekoodia

补充申报方法

1 2 viikkoa sitten
vanhempi
commit
993b724842
2 muutettua tiedostoa jossa 51 lisäystä ja 0 poistoa
  1. 41 0
      common/period.go
  2. 10 0
      common/rod_utils.go

+ 41 - 0
common/period.go

@@ -355,3 +355,44 @@ func GetLastYear() string {
 func WaitElementX5(page *rod.Page, xpath string) *rod.Element {
 	return WaitElementXFoTimes(page, xpath, 5)
 }
+
+// 获取上一年的最后一天
+func GetLastYearLastDate() string {
+	now := time.Now()
+	lastYear := now.AddDate(-1, 0, 0)
+	lastDayOfLastYear := time.Date(lastYear.Year(), 12, 31, 0, 0, 0, 0, time.Local)
+	return lastDayOfLastYear.Format(`2006-01-02`)
+}
+
+// 获取本账期开始和结束日期
+func GetQuarterStartTimeAndEndTime(period string) (string, string) {
+	quarterStart := ""
+	quarterEnd := ""
+	quarter := math.Ceil(StrToFloat(period[4:6])/3) - 1
+	if quarter == 0 { //第一季度
+		quarterStart = period[0:4] + "-01-01"
+		quarterEnd = period[0:4] + "-03-31"
+	}
+	if quarter == 1 { //第二季度
+		quarterStart = period[0:4] + "-04-01"
+		quarterEnd = period[0:4] + "-06-30"
+	}
+	if quarter == 2 { //第三季度
+		quarterStart = period[0:4] + "-07-01"
+		quarterEnd = period[0:4] + "-09-30"
+	}
+	if quarter == 3 { //第四季度
+		quarterStart = period[0:4] + "-10-01"
+		quarterEnd = period[0:4] + "-12-31"
+	}
+	return quarterStart, quarterEnd
+}
+
+func GetCurrentPeriod3() string { //仅本期报税使用
+	tm := time.Unix(time.Now().Unix(), 0)
+	currentYear, currentMonth, _ := tm.Date()
+	currentLocation := tm.Location()
+	firstOfMonth := time.Date(currentYear, currentMonth, 10, 0, 0, 0, 0, currentLocation)
+	period := firstOfMonth.AddDate(0, -1, 0).Format("2006-01") // 当前账期-1
+	return period
+}

+ 10 - 0
common/rod_utils.go

@@ -565,3 +565,13 @@ func MustElementX30(page *rod.Page, xpath string) *rod.Element {
 	}
 	return nil
 }
+
+func WaitHasX10(page *rod.Page, xpath string) (x bool) {
+	for i := 0; i < 10; i++ {
+		x, _, _ = HasX(page, xpath)
+		if !x {
+			utils.Sleep(1)
+		}
+	}
+	return x
+}