zwxi 1 month ago
parent
commit
6796d4ca2d

+ 37 - 5
controllers/base_from_hisugar.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"eta/eta_index_lib/logic"
 	"eta/eta_index_lib/models"
+	"eta/eta_index_lib/services"
 	"eta/eta_index_lib/utils"
 	"strconv"
 	"time"
@@ -46,14 +47,14 @@ func (this *HisugarController) Add() {
 	cacheKey = utils.CACHE_EDB_DATA_ADD + strconv.Itoa(source) + "_" + req.EdbCode
 	if !utils.Rc.IsExist(cacheKey) {
 		utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
-		err = models.AddEdbDataFromOilchem(req.EdbCode)
+		err = models.AddEdbDataFromHisugar(req.EdbCode)
 		if err != nil {
 			br.Msg = "获取指标信息失败!"
-			br.ErrMsg = "获取指标信息失败 AddEdbDataFromCoal,Err:" + err.Error()
+			br.ErrMsg = "获取指标信息失败 AddEdbDataFromHisugar,Err:" + err.Error()
 			return
 		}
 		br.Ret = 200
-		br.Success = true
+		br.Success =  true
 		br.Msg = "获取成功"
 	} else {
 		br.Ret = 501
@@ -111,10 +112,10 @@ func (this *HisugarController) Refresh() {
 		return
 	}
 
-	err = models.RefreshEdbDataFromOilchem(req.EdbInfoId, req.EdbCode, req.StartDate)
+	err = models.RefreshEdbDataFromHisugar(req.EdbInfoId, req.EdbCode, req.StartDate)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "刷新指标信息失败!"
-		br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromCoal,Err:" + err.Error()
+		br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromHisugar,Err:" + err.Error()
 		return
 	}
 	// 更新指标最大最小值
@@ -133,4 +134,35 @@ func (this *HisugarController) Refresh() {
 	br.Msg = "获取成功"
 }
 
+// HandleEdbData
+// @Title 处理泛糖科技指标的接口
+// @Description 处理泛糖科技指标的接口
+// @Success 200 string "操作成功"
+// @router /handle/edb_data [post]
+func (this *HisugarController) HandleEdbData() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.HandleHisugarEdbDataReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if err = services.HandleHisugarIndex(req.List); err != nil {
+		br.Msg = "处理失败"
+		br.ErrMsg = "处理失败,Err:" + err.Error()
+		return
+	}
 
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "处理成功"
+}

+ 17 - 19
models/base_from_hisugar.go

@@ -232,25 +232,6 @@ func GetBaseFromHisugarDataByCondition(condition string, pars []interface{}) (li
 }
 
 
-type BaseFromHisugarIndexReq struct {
-	BaseFromHisugarIndexId int       // 主键ID
-	IndexCode              string    // 指标编码
-	IndexName              string    // 指标名称
-	ClassifyId             uint      // 分类ID
-	Unit                   string    // 单位
-	Source                 string    // 数据来源
-	Frequency              string    // 频度
-	Describe               string    // 指标描述
-	DataTime               string    // 数据日期
-	Value                  string   // 数据值
-	Sort                   int       // 排序
-	CreateTime             time.Time // 创建时间
-	ModifyTime             time.Time // 修改时间
-	IndexNameStr           string    // 指标名称字符串
-	MarketName             string    // 市场名称
-}
-
-
 type HandleHisugarEdbDataReq struct {
 	List []*BaseFromHisugarIndexReq
 }
@@ -275,4 +256,21 @@ func UpdateBaseFromHisugarData(value , indexCode, dataTime string) (err error) {
 	sql := `UPDATE base_from_sci99_data SET value=?,modify_time=NOW() WHERE index_code = ? AND data_time = ? `
 	_, err = o.Raw(sql, value, indexCode, dataTime).Exec()
 	return
+}
+
+type BaseFromHisugarIndexReq struct {
+	BaseFromHisugarIndexId int       // 主键ID
+	IndexCode              string    // 指标编码
+	IndexName              string    // 指标名称
+	ClassifyId             uint      // 分类ID
+	Unit                   string    // 单位
+	Frequency              string    // 频度
+	Describe               string    // 指标描述
+	DataTime               string    // 数据日期
+	Sort                   int       // 排序
+	CreateTime             time.Time // 创建时间
+	ModifyTime             time.Time // 修改时间
+	IndexNameStr           string    // 指标名称字符串
+	MarketName             string    // 市场名称
+	Value                  string    // 值
 }

+ 2 - 0
models/db.go

@@ -168,6 +168,8 @@ func initBaseIndex() {
 		new(BaseFromBusinessData), // 数据源中自有数据的明细数据表
 		new(BaseFromOilchemIndex),
 		new(BaseFromOilchemData),
+		new(BaseFromHisugarIndex),
+		new(BaseFromHisugarData),
 	)
 }
 

+ 9 - 0
routers/commentsRouter.go

@@ -727,6 +727,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_index_lib/controllers:HisugarController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:HisugarController"],
+        beego.ControllerComments{
+            Method: "HandleEdbData",
+            Router: `/handle/edb_data`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_index_lib/controllers:HisugarController"] = append(beego.GlobalControllerRouter["eta/eta_index_lib/controllers:HisugarController"],
         beego.ControllerComments{
             Method: "Refresh",

+ 154 - 182
services/base_from_hisugar.go

@@ -1,184 +1,156 @@
 package services
 
-//var IndexCodeMap = make(map[string]string)
-//var IndexMap = make(map[string]*models.BaseFromOilchemIndex)
-//func HandleOilchemIndex(list []*models.BaseFromOilchemIndexReq) (err error) {
-//	allCode, e := models.GetBaseFromOilchemIndex()
-//	if e != nil {
-//		err = e
-//		fmt.Println("select Code err:", err)
-//		utils.FileLog.Info("GetBaseFromOilchemIndex err:", err)
-//		return
-//	}
-//
-//	for _, item := range allCode {
-//		IndexCodeMap[item.IndexName] = item.IndexCode
-//		IndexMap[item.IndexName] = item
-//	}
-//
-//	for _, v := range list {
-//		indexCode, needAdd := OilchemIndexCodeGenerator(v.IndexName, v.IndexNameStr, v.MarketName)
-//		if needAdd {
-//			item := models.BaseFromOilchemIndex{
-//				IndexCode:              indexCode,
-//				IndexName:              v.IndexName,
-//				ClassifyId:             v.ClassifyId,
-//				Unit:                   v.Unit,
-//				Frequency:              v.Frequency,
-//				Describe:               v.Describe,
-//				Sort:                   v.Sort,
-//				CreateTime:             v.CreateTime,
-//				ModifyTime:             v.ModifyTime,
-//			}
-//			id, e := models.AddBaseFromOilchemIndex(&item)
-//			if e != nil {
-//				err = e
-//				fmt.Println("AddBaseFromOilchemIndexMuti err:", err)
-//				utils.FileLog.Info("AddBaseFromOilchemIndexMuti err:", err)
-//				return
-//			}
-//			item.BaseFromOilchemIndexId = int(id)
-//			IndexMap[item.IndexName] = &item
-//		}
-//
-//
-//		//获取指标数据信息
-//		data, e := models.GetBaseFromOilchemData(indexCode, v.DataTime)
-//		if e != nil && e.Error() != utils.ErrNoRow() {
-//			err = e
-//			fmt.Println("select err:", err)
-//			utils.FileLog.Info("GetBaseFromTradeSci99IndexAll err:", err)
-//		}
-//
-//		if data != nil {
-//			if data.Value != v.Value {
-//				// 更新
-//				fmt.Println("更新指标:", indexCode+v.DataTime)
-//				utils.FileLog.Info("更新指标:", indexCode+v.DataTime)
-//				e = models.UpdateBaseFromOilchemData(v.Value, indexCode, v.DataTime)
-//				if e != nil {
-//					err = e
-//					fmt.Println("Error update into database:", err)
-//					utils.FileLog.Info("Error update into database:", err)
-//					return
-//				}
-//			}
-//		} else {
-//			// 新增
-//			dataItem := models.BaseFromOilchemData{
-//				BaseFromOilchemIndexId: IndexMap[v.IndexName].BaseFromOilchemIndexId,
-//				IndexCode:              indexCode,
-//				DataTime:               v.DataTime,
-//				Value:                  v.Value,
-//				CreateTime:             v.CreateTime,
-//				ModifyTime:             v.ModifyTime,
-//			}
-//			fmt.Println("新增数据:", indexCode+v.DataTime)
-//			utils.FileLog.Info("新增数据:", indexCode+v.DataTime)
-//
-//			_,e = models.AddBaseFromOilchemData(&dataItem)
-//			if e != nil {
-//				err = e
-//				fmt.Println("Error inserting into database:", err)
-//				utils.FileLog.Info("Error inserting into database:", err)
-//				return
-//			}
-//		}
-//	}
-//
-//	return
-//}
-//
-//
-//func OilchemIndexCodeGenerator(indexName, indexCodeStr, marketSampleName string) (indexCode string, needAdd bool) {
-//	strResult := ""
-//	indexCode, _ = IndexCodeMap[indexName]
-//	if indexCode == "" {
-//		//首字母
-//		a := pinyin.NewArgs()
-//		a.Fallback = func(r rune, a pinyin.Args) []string {
-//			return []string{string(r)}
-//		}
-//		indexCodeStr = strings.Replace(indexCodeStr, "(", "", -1)
-//		indexCodeStr = strings.Replace(indexCodeStr, ")", "", -1)
-//		rows := pinyin.Pinyin(indexCodeStr, a)
-//		for i := 0; i < len(rows); i++ {
-//			//strResult += rows[i][0]
-//			if len(rows[i]) != 0 {
-//				str := rows[i][0]
-//				pi := str[0:1]
-//				strResult += pi
-//			}
-//		}
-//
-//		// 处理括号内名称
-//		if marketSampleName != "" {
-//			if province, ok := ProvinceMap[marketSampleName]; ok {
-//				strResult += province
-//			} else {
-//				a := pinyin.NewArgs()
-//				rows := pinyin.LazyPinyin(marketSampleName, a)
-//				for i := 0; i < len(rows); i++ {
-//					strResult += rows[i]
-//				}
-//				if len(rows) == 0 {
-//					strResult += marketSampleName
-//				}
-//			}
-//		}
-//
-//
-//		// 去除特殊符号
-//		strResult = strings.Replace(strResult, " ", "", -1)
-//		strResult = strings.Replace(strResult, "-", "", -1)
-//		strResult = strings.Replace(strResult, "/", "", -1)
-//		strResult = strings.Replace(strResult, "#", "", -1)
-//		strResult = strings.Replace(strResult, ":", "", -1)
-//		strResult = strings.Replace(strResult, "(", "", -1)
-//		strResult = strings.Replace(strResult, ")", "", -1)
-//
-//
-//		needAdd = true
-//		strResult = "lzzxw" + strResult
-//		indexCode = strings.Replace(strResult, " ", "", -1)
-//		IndexCodeMap[indexName] = indexCode
-//	}
-//	return
-//}
-//
-//var ProvinceMap = map[string]string{
-//	"上海":  "shanghai",
-//	"云南":  "yunnan",
-//	"内蒙古": "innermongolia",
-//	"北京":  "beijing",
-//	"台湾":  "taiwan",
-//	"吉林":  "jilin",
-//	"四川":  "sichuan",
-//	"天津":  "tianjin",
-//	"宁夏":  "ningxia",
-//	"安徽":  "anhui",
-//	"山东":  "shandong",
-//	"山西":  "shanxi",
-//	"广东":  "guangdong",
-//	"广西":  "guangxi",
-//	"新疆":  "xinjiang",
-//	"江苏":  "jiangsu",
-//	"江西":  "jiangxi",
-//	"河北":  "hebei",
-//	"河南":  "henan",
-//	"浙江":  "zhejiang",
-//	"海南":  "hainan",
-//	"湖北":  "hubei",
-//	"湖南":  "hunan",
-//	"澳门":  "macao",
-//	"甘肃":  "gansu",
-//	"福建":  "fujian",
-//	"西藏":  "tibet",
-//	"贵州":  "guizhou",
-//	"辽宁":  "liaoning",
-//	"重庆":  "chongqing",
-//	"陕西":  "shaanxi",
-//	"青海":  "qinhai",
-//	"香港":  "hongkong",
-//	"黑龙江": "heilongjiang",
-//}
+import (
+	"eta/eta_index_lib/models"
+	"eta/eta_index_lib/utils"
+	"fmt"
+	"github.com/mozillazg/go-pinyin"
+	"strings"
+)
+
+var HisugarIndexCodeMap = make(map[string]string)
+var HisugarIndexMap = make(map[string]*models.BaseFromHisugarIndex)
+func HandleHisugarIndex(list []*models.BaseFromHisugarIndexReq) (err error) {
+	allCode, e := models.GetBaseFromHisugarIndex()
+	if e != nil {
+		err = e
+		fmt.Println("select Code err:", err)
+		utils.FileLog.Info("GetBaseFromHisugarIndex err:", err)
+		return
+	}
+
+	for _, item := range allCode {
+		HisugarIndexCodeMap[item.IndexName] = item.IndexCode
+		HisugarIndexMap[item.IndexName] = item
+	}
+
+	for _, v := range list {
+		indexCode, needAdd := HisugarIndexCodeGenerator(v.IndexName, v.IndexNameStr, v.MarketName)
+		if needAdd {
+			item := models.BaseFromHisugarIndex{
+				IndexCode:              indexCode,
+				IndexName:              v.IndexName,
+				ClassifyId:             v.ClassifyId,
+				Unit:                   v.Unit,
+				Frequency:              v.Frequency,
+				Describe:               v.Describe,
+				Sort:                   v.Sort,
+				CreateTime:             v.CreateTime,
+				ModifyTime:             v.ModifyTime,
+			}
+			id, e := models.AddBaseFromHisugarIndex(&item)
+			if e != nil {
+				err = e
+				fmt.Println("AddBaseFromHisugarIndexMuti err:", err)
+				utils.FileLog.Info("AddBaseFromHisugarIndexMuti err:", err)
+				return
+			}
+			item.BaseFromHisugarIndexId = int(id)
+			HisugarIndexMap[item.IndexName] = &item
+		}
+
+
+		//获取指标数据信息
+		data, e := models.GetBaseFromHisugarData(indexCode, v.DataTime)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			err = e
+			fmt.Println("select err:", err)
+			utils.FileLog.Info("GetBaseFromTradeSci99IndexAll err:", err)
+		}
+
+		if data != nil {
+			if data.Value != v.Value {
+				// 更新
+				fmt.Println("更新指标:", indexCode+v.DataTime)
+				utils.FileLog.Info("更新指标:", indexCode+v.DataTime)
+				e = models.UpdateBaseFromHisugarData(v.Value, indexCode, v.DataTime)
+				if e != nil {
+					err = e
+					fmt.Println("Error update into database:", err)
+					utils.FileLog.Info("Error update into database:", err)
+					return
+				}
+			}
+		} else {
+			// 新增
+			dataItem := models.BaseFromHisugarData{
+				BaseFromHisugarIndexId: HisugarIndexMap[v.IndexName].BaseFromHisugarIndexId,
+				IndexCode:              indexCode,
+				DataTime:               v.DataTime,
+				Value:                  v.Value,
+				CreateTime:             v.CreateTime,
+				ModifyTime:             v.ModifyTime,
+			}
+			fmt.Println("新增数据:", indexCode+v.DataTime)
+			utils.FileLog.Info("新增数据:", indexCode+v.DataTime)
+
+			_,e = models.AddBaseFromHisugarData(&dataItem)
+			if e != nil {
+				err = e
+				fmt.Println("Error inserting into database:", err)
+				utils.FileLog.Info("Error inserting into database:", err)
+				return
+			}
+		}
+	}
+
+	return
+}
+
+
+func HisugarIndexCodeGenerator(indexName, indexCodeStr, marketSampleName string) (indexCode string, needAdd bool) {
+	strResult := ""
+	indexCodeStr = indexName
+	indexCode, _ = HisugarIndexCodeMap[indexName]
+	if indexCode == "" {
+		//首字母
+		a := pinyin.NewArgs()
+		a.Fallback = func(r rune, a pinyin.Args) []string {
+			return []string{string(r)}
+		}
+		indexCodeStr = strings.Replace(indexCodeStr, "(", "", -1)
+		indexCodeStr = strings.Replace(indexCodeStr, ")", "", -1)
+		rows := pinyin.Pinyin(indexCodeStr, a)
+		for i := 0; i < len(rows); i++ {
+			//strResult += rows[i][0]
+			if len(rows[i]) != 0 {
+				str := rows[i][0]
+				pi := str[0:1]
+				strResult += pi
+			}
+		}
+
+		// 处理括号内名称
+		if marketSampleName != "" {
+			if province, ok := ProvinceMap[marketSampleName]; ok {
+				strResult += province
+			} else {
+				a := pinyin.NewArgs()
+				rows := pinyin.LazyPinyin(marketSampleName, a)
+				for i := 0; i < len(rows); i++ {
+					strResult += rows[i]
+				}
+				if len(rows) == 0 {
+					strResult += marketSampleName
+				}
+			}
+		}
+
+
+		// 去除特殊符号
+		strResult = strings.Replace(strResult, " ", "", -1)
+		strResult = strings.Replace(strResult, "-", "", -1)
+		strResult = strings.Replace(strResult, "/", "", -1)
+		strResult = strings.Replace(strResult, "#", "", -1)
+		strResult = strings.Replace(strResult, ":", "", -1)
+		strResult = strings.Replace(strResult, "(", "", -1)
+		strResult = strings.Replace(strResult, ")", "", -1)
+
+
+		needAdd = true
+		strResult = "ftkj" + strResult
+		indexCode = strings.Replace(strResult, " ", "", -1)
+		HisugarIndexCodeMap[indexName] = indexCode
+	}
+	return
+}

+ 1 - 1
utils/constants.go

@@ -200,7 +200,7 @@ const (
 	DATA_SOURCE_NAME_CCF                                  = `CCF`  // CCF化纤信息
 	DATA_SOURCE_NAME_SCI_HQ                               = `卓创红期` // 卓创红期
 	DATA_SOURCE_NAME_OILCHEM                              = `隆众资讯` // 隆众资讯 -> 89
-	DATA_SOURCE_NAME_HISUGAR                              = `泛糖科技` // 泛糖科技 -> 91
+	DATA_SOURCE_NAME_HISUGAR                              = `泛糖科技` // 泛糖科技 -> 93
 )
 
 // 基础数据初始化日期