xiexiaoyuan пре 2 година
родитељ
комит
7fbc7ae390
3 измењених фајлова са 14 додато и 9 уклоњено
  1. 2 0
      go.mod
  2. 2 0
      go.sum
  3. 10 9
      services/source_changes_visitors_covid.go

+ 2 - 0
go.mod

@@ -12,6 +12,8 @@ require (
 	github.com/go-sql-driver/mysql v1.6.0
 	github.com/mozillazg/go-pinyin v0.19.0
 	github.com/rdlucklib/rdluck_tools v1.0.2
+	github.com/shopspring/decimal v1.3.1
 	github.com/tealeg/xlsx v1.0.5
+	golang.org/x/text v0.3.6
 	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
 )

+ 2 - 0
go.sum

@@ -285,6 +285,8 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
+github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
+github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
 github.com/siddontang/go v0.0.0-20170517070808-cb568a3e5cc0/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
 github.com/siddontang/goredis v0.0.0-20150324035039-760763f78400/go.mod h1:DDcKzU3qCuvj/tPnimWSsZZzvk9qvkvrIL5naVBPh5s=
 github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=

+ 10 - 9
services/source_changes_visitors_covid.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"github.com/chromedp/cdproto/browser"
 	"github.com/chromedp/chromedp"
+	"github.com/shopspring/decimal"
 	"hongze/hongze_data_crawler/models"
 	"hongze/hongze_data_crawler/services/alarm_msg"
 	"hongze/hongze_data_crawler/utils"
@@ -14,7 +15,6 @@ import (
 	"log"
 	"os"
 	"path/filepath"
-	"strconv"
 	"time"
 )
 
@@ -103,19 +103,19 @@ func AddSourceChangesVisitorsCovid() (err error) {
 			}
 
 			tmp.RetailAndRecreation = row[3]
-			retailAndRecreation, _ := strconv.ParseFloat(tmp.RetailAndRecreation, 32)
+			retailAndRecreation, _ := decimal.NewFromString(tmp.RetailAndRecreation)
 			tmp.GroceryAndPharmacy = row[4]
-			groceryAndPharmacy, _ := strconv.ParseFloat(tmp.GroceryAndPharmacy, 32)
+			groceryAndPharmacy, _ := decimal.NewFromString(tmp.GroceryAndPharmacy)
 			tmp.Residential = row[5]
-			residential, _ := strconv.ParseFloat(tmp.Residential, 32)
+			residential, _ := decimal.NewFromString(tmp.Residential)
 			tmp.TransitStations = row[6]
-			transitStations, _ := strconv.ParseFloat(tmp.TransitStations, 32)
+			transitStations, _ := decimal.NewFromString(tmp.TransitStations)
 			tmp.Parks = row[7]
-			parks, _ := strconv.ParseFloat(tmp.Parks, 32)
+			parks, _ := decimal.NewFromString(tmp.Parks)
 			tmp.Workplaces = row[8]
-			workplaces, _ := strconv.ParseFloat(tmp.Workplaces, 32)
-			total := retailAndRecreation + groceryAndPharmacy + residential + transitStations + parks + workplaces
-			tmp.Total = strconv.FormatFloat(total,'f',5,32)
+			workplaces, _ := decimal.NewFromString(tmp.Workplaces)
+			total := retailAndRecreation.Add(groceryAndPharmacy).Add(residential).Add(transitStations).Add(parks).Add(workplaces)
+			tmp.Total = total.String()
 			tmp.CreateTime = now
 			tmp.ModifyTime = now
 
@@ -146,6 +146,7 @@ func AddSourceChangesVisitorsCovid() (err error) {
 		err = errors.New("删除文件失败 "+ err.Error())
 		return
 	}*/
+	println("入库成功")
 	return
 }