瀏覽代碼

兼容钢联化工指标导入日期

xyxie 1 年之前
父節點
當前提交
3636793eeb
共有 4 個文件被更改,包括 40 次插入5 次删除
  1. 1 0
      go.mod
  2. 7 0
      go.sum
  3. 21 5
      services/base_from_mysteel_chemical.go
  4. 11 0
      utils/common.go

+ 1 - 0
go.mod

@@ -3,6 +3,7 @@ module eta/eta_index_lib
 go 1.21.7
 
 require (
+	github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
 	github.com/beego/bee/v2 v2.1.0
 	github.com/beego/beego/v2 v2.1.0
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible

+ 7 - 0
go.sum

@@ -8,6 +8,8 @@ github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGn
 github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk=
 github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02 h1:o2oaBQGTzO+xNh12e7xWkphNe7H2DTiWv1ml9a2P9PQ=
 github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20211218165449-dd623ecc2f02/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
+github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA=
+github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
 github.com/astaxie/beego v1.12.3/go.mod h1:p3qIm0Ryx7zeBHLljmd7omloyca1s4yu1a8kM1FkpIA=
 github.com/beego/bee/v2 v2.1.0 h1:4WngbAnkvVOyKy74WXcRH3clon76wkjhuzrV2mx2fQU=
 github.com/beego/bee/v2 v2.1.0/go.mod h1:wDhKy5TNxv46LHKsK2gyxo38ObCOm9PbCN89lWHK3EU=
@@ -123,6 +125,7 @@ github.com/lib/pq v1.10.5 h1:J+gdV2cUmX7ZqL2B0lFcW0m+egaHC2V3lpO8nWxyYiQ=
 github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
+github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
 github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -181,8 +184,10 @@ github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+Pymzi
 github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
 github.com/rdlucklib/rdluck_tools v1.0.3 h1:iOtK2QPlPQ6CL6c1htCk5VnFCHzyG6DCfJtunrMswK0=
 github.com/rdlucklib/rdluck_tools v1.0.3/go.mod h1:9Onw9o4w19C8KE5lxb8GyxgRBbZweRVkQSc79v38EaA=
+github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
 github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
+github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
@@ -199,6 +204,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
@@ -271,5 +277,6 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 21 - 5
services/base_from_mysteel_chemical.go

@@ -80,8 +80,16 @@ func handleIndex(indexItem *models.HandleMysteelIndex) (err error) {
 		indexObj.Unit = indexItem.Unit
 		indexObj.Source = indexItem.Source
 		indexObj.Describe = indexItem.Describe
-		indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, indexItem.StartDate, time.Local)
-		indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, indexItem.EndDate, time.Local)
+		indexObj.StartDate, err = utils.DealExcelDate(indexItem.StartDate)
+		if err != nil {
+			fmt.Println("utils.DealExcelDate err:" + indexItem.StartDate + err.Error())
+			return
+		}
+		indexObj.EndDate, err = utils.DealExcelDate(indexItem.EndDate)
+		if err != nil {
+			fmt.Println("utils.DealExcelDate err:" + indexItem.EndDate + err.Error())
+			return
+		}
 		indexObj.Frequency = indexItem.Frequency
 		//indexObj.CreateTime = time.Now().Local()
 		//indexObj.ModifyTime = time.Now().Local()
@@ -98,8 +106,16 @@ func handleIndex(indexItem *models.HandleMysteelIndex) (err error) {
 		indexObj.Unit = indexItem.Unit
 		indexObj.Source = indexItem.Source
 		indexObj.Describe = indexItem.Describe
-		indexObj.StartDate, _ = time.ParseInLocation(utils.FormatDate, indexItem.StartDate, time.Local)
-		indexObj.EndDate, _ = time.ParseInLocation(utils.FormatDate, indexItem.EndDate, time.Local)
+		indexObj.StartDate, err = utils.DealExcelDate(indexItem.StartDate)
+		if err != nil {
+			fmt.Println("utils.DealExcelDate err:" + indexItem.StartDate + err.Error())
+			return
+		}
+		indexObj.EndDate, err = utils.DealExcelDate(indexItem.EndDate)
+		if err != nil {
+			fmt.Println("utils.DealExcelDate err:" + indexItem.EndDate + err.Error())
+			return
+		}
 		indexObj.Frequency = indexItem.Frequency
 		indexObj.ModifyTime = time.Now()
 		indexId = item.BaseFromMysteelChemicalIndexId
@@ -149,7 +165,7 @@ func handleIndex(indexItem *models.HandleMysteelIndex) (err error) {
 	// 遍历excel数据,然后跟现有的数据做校验,不存在则入库
 	for date, value := range indexItem.ExcelDataMap {
 		if findData, ok := exitDataMap[date]; !ok {
-			dateTime, err := time.ParseInLocation(utils.FormatDate, date, time.Local)
+			dateTime, err := utils.DealExcelDate(date)
 			if err != nil {
 				fmt.Println("time.ParseInLocation Err:" + err.Error())
 				return err

+ 11 - 0
utils/common.go

@@ -8,6 +8,7 @@ import (
 	"encoding/hex"
 	"encoding/json"
 	"fmt"
+	"github.com/araddon/dateparse"
 	"github.com/shopspring/decimal"
 	"image"
 	"image/png"
@@ -1201,3 +1202,13 @@ func GetEdbRefreshEndDate(endDate string) string {
 
 	return endDate
 }
+
+func DealExcelDate(date string) (newDate time.Time, err error) {
+	newDate, err = dateparse.ParseAny(date)
+	if err != nil {
+		return
+	}
+
+	newDate = time.Date(newDate.Year(), newDate.Month(), newDate.Day(), 0, 0, 0, 0, time.Local)
+	return
+}