Browse Source

新增基础指标

longyu 3 years ago
parent
commit
ca531a53e5

+ 107 - 0
controllers/base_from_gie.go

@@ -0,0 +1,107 @@
+package controllers
+
+import (
+	"encoding/json"
+	"hongze/hongze_edb_lib/models"
+	"hongze/hongze_edb_lib/utils"
+	"strconv"
+	"time"
+)
+
+//欧洲天然气
+type GieController struct {
+	BaseAuthController
+}
+
+// @Title 新增欧洲天然气指标接口
+// @Description 新增欧洲天然气指标接口
+// @Success 200 {object} models.AddEdbInfoReq
+// @router /add [post]
+func (this *GieController) Add() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	source := utils.DATA_SOURCE_GIE
+	var req models.AddEdbInfoReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	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.AddEdbDataFromGie(req.EdbCode)
+		if err != nil {
+			br.Msg = "获取指标信息失败!"
+			br.ErrMsg = "获取指标信息失败 AddEdbDataFromGie,Err:" + err.Error()
+			return
+		}
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+	} else {
+		br.Ret = 501
+		br.Success = true
+		br.Msg = "系统处理中,请稍后重试"
+	}
+}
+
+// @Title 刷新欧洲天然气指标接口
+// @Description 刷新欧洲天然气指标接口
+// @Success 200 {object} models.RefreshEdbInfoReq
+// @router /refresh [post]
+func (this *GieController) Refresh() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	source := utils.DATA_SOURCE_GIE
+	var req models.RefreshEdbInfoReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	if req.EdbInfoId <= 0 {
+		br.Msg = "请输入指标ID!"
+		br.ErrMsg = "请输入指标ID"
+		return
+	}
+	cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
+	if !utils.Rc.IsExist(cacheKey) {
+		utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
+		err = models.RefreshEdbDataFromGie(req.EdbInfoId, req.EdbCode, req.StartDate)
+		if err != nil {
+			br.Msg = "刷新指标信息失败!"
+			br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromGie,Err:" + err.Error()
+			return
+		}
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+	} else {
+		br.Ret = 501
+		br.Success = true
+		br.Msg = "系统处理中,请稍后重试"
+	}
+}

+ 108 - 0
controllers/base_from_shfe.go

@@ -0,0 +1,108 @@
+package controllers
+
+import (
+	"encoding/json"
+	"hongze/hongze_edb_lib/models"
+	"hongze/hongze_edb_lib/utils"
+	"strconv"
+	"time"
+)
+
+//上期能源
+type ShfeController struct {
+	BaseAuthController
+}
+
+
+// @Title 新增上期能源指标接口
+// @Description 新增上期能源指标接口
+// @Success 200 {object} models.AddEdbInfoReq
+// @router /add [post]
+func (this *ShfeController) Add() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	source := utils.DATA_SOURCE_CFFEX
+	var req models.AddEdbInfoReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	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.AddEdbDataFromShfe(req.EdbCode)
+		if err != nil {
+			br.Msg = "获取指标信息失败!"
+			br.ErrMsg = "获取指标信息失败 AddEdbDataFromShfe,Err:" + err.Error()
+			return
+		}
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+	} else {
+		br.Ret = 501
+		br.Success = true
+		br.Msg = "系统处理中,请稍后重试"
+	}
+}
+
+// @Title 刷新上期能源指标接口
+// @Description 刷新上期能源指标接口
+// @Success 200 {object} models.RefreshEdbInfoReq
+// @router /refresh [post]
+func (this *ShfeController) Refresh() {
+	br := new(models.BaseResponse).Init()
+	var cacheKey string
+	defer func() {
+		utils.Rc.Delete(cacheKey)
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	source := utils.DATA_SOURCE_CFFEX
+	var req models.RefreshEdbInfoReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.EdbCode == "" {
+		br.Msg = "请输入指标编码!"
+		br.ErrMsg = "请输入指标编码,指标编码为空"
+		return
+	}
+	if req.EdbInfoId <= 0 {
+		br.Msg = "请输入指标ID!"
+		br.ErrMsg = "请输入指标ID"
+		return
+	}
+	cacheKey = utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(source) + "_" + req.EdbCode
+	if !utils.Rc.IsExist(cacheKey) {
+		utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
+		err = models.RefreshEdbDataFromShfe(req.EdbInfoId, req.EdbCode, req.StartDate)
+		if err != nil {
+			br.Msg = "刷新指标信息失败!"
+			br.ErrMsg = "刷新指标信息失败 RefreshEdbDataFromShfe,Err:" + err.Error()
+			return
+		}
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+	} else {
+		br.Ret = 501
+		br.Success = true
+		br.Msg = "系统处理中,请稍后重试"
+	}
+}

+ 299 - 0
models/base_from_gie.go

@@ -0,0 +1,299 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_edb_lib/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type BaseFromTradeEicIndex struct {
+	BaseFromEicIndexId     int `orm:"column(base_from_eic_index_id);pk"`
+	Country                string
+	Type                   string
+	EicCode                string
+	ShortName              string
+	Name                   string
+	Status                 string
+	GasDayStartedOn        string
+	GasInStorage           string
+	GasInStorageCode       string
+	Full                   string
+	FullCode               string
+	Trend                  string
+	TrendCode              string
+	Injection              string
+	InjectionCode          string
+	Withdrawal             string
+	WithdrawalCode         string
+	WorkingGasVolume       string
+	WorkingGasVolumeCode   string
+	InjectionCapacity      string
+	InjectionCapacityCode  string
+	WithdrawalCapacity     string
+	WithdrawalCapacityCode string
+	Info                   string
+	CreateTime             time.Time
+	ModifyTime             time.Time
+}
+
+func GetBaseFromEicDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeEicIndex, err error) {
+	o := orm.NewOrm()
+	var name string
+	if suffix == "" {
+		name = "eic_code"
+	} else if suffix == "GS" {
+		name = "gas_in_storage_code"
+	} else if suffix == "F" {
+		name = "full_code"
+	} else if suffix == "T" {
+		name = "trend_code"
+	} else if suffix == "In" {
+		name = "injection_code"
+	} else if suffix == "Out" {
+		name = "withdrawal_code"
+	} else if suffix == "WGV" {
+		name = "working_gas_volume_code"
+	} else if suffix == "IC" {
+		name = "injection_capacity_code"
+	} else if suffix == "WC" {
+		name = "withdrawal_capacity_code"
+	}
+	sql := `SELECT * FROM base_from_trade_eic_index WHERE %s=? `
+	sql = fmt.Sprintf(sql, name)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetGieDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromTradeEicIndex, err error) {
+	sql := ` SELECT * FROM base_from_trade_eic_index WHERE 1=1 `
+	o := orm.NewOrm()
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY gas_day_started_on DESC `
+	fmt.Println(sql, pars)
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+//新增上期能源指标数据
+func AddEdbDataFromGie(edbCode string) (err error) {
+	var suffix string
+	l := len(edbCode)
+	if strings.Contains(edbCode[l-2:], "GS") {
+		suffix = "GS"
+	} else if strings.Contains(edbCode[l-1:], "F") {
+		suffix = "F"
+	} else if strings.Contains(edbCode[l-1:], "T") {
+		suffix = "T"
+	} else if strings.Contains(edbCode[l-2:], "In") {
+		suffix = "In"
+	} else if strings.Contains(edbCode[l-3:], "Out") {
+		suffix = "Out"
+	} else if strings.Contains(edbCode[l-3:], "WGV") {
+		suffix = "WGV"
+	} else if strings.Contains(edbCode[l-2:], "IC") {
+		suffix = "IC"
+	} else if strings.Contains(edbCode[l-2:], "WC") {
+		suffix = "WC"
+	} else {
+		suffix = ""
+	}
+
+	o := orm.NewOrm()
+	eicBaseDataAll, err := GetBaseFromEicDataAllByIndexCode(edbCode, suffix)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println("GetBaseFromEicDataAllByIndexCode err:", err)
+		return
+	}
+
+	var isAdd bool
+	addSql := ` INSERT INTO edb_data_gie(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
+	existMap := make(map[string]string)
+
+	for _, sv := range eicBaseDataAll {
+		eDate := sv.GasDayStartedOn
+		dataTime, err := time.Parse(utils.FormatDate, eDate)
+		if err != nil {
+			fmt.Println("time.Parse Err:" + eDate)
+			return err
+		}
+		timestamp := dataTime.UnixNano() / 1e6
+		timeStr := fmt.Sprintf("%d", timestamp)
+		//var name string
+		if _, ok := existMap[eDate]; !ok {
+			if suffix == "GS" {
+				//name = "gas_in_storage"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.GasInStorage)
+				existMap[eDate] = sv.GasInStorage
+			} else if suffix == "F" {
+				//name = "full"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.Full)
+				existMap[eDate] = sv.Full
+			} else if suffix == "T" {
+				//name = "trend"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.Trend)
+				existMap[eDate] = sv.Trend
+			} else if suffix == "In" {
+				//name = "injection"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.Injection)
+				existMap[eDate] = sv.Injection
+			} else if suffix == "Out" {
+				//name = "withdrawal"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.Withdrawal)
+				existMap[eDate] = sv.Withdrawal
+			} else if suffix == "WGV" {
+				//name = "working_gas_volume"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.WorkingGasVolume)
+				existMap[eDate] = sv.WorkingGasVolume
+			} else if suffix == "IC" {
+				//name = "injection_capacity"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.InjectionCapacity)
+				existMap[eDate] = sv.InjectionCapacity
+			} else if suffix == "WC" {
+				//name = "withdrawal_capacity"
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.WithdrawalCapacity)
+				existMap[eDate] = sv.WithdrawalCapacity
+			}
+			isAdd = true
+		}
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		utils.FileLog.Info("addSql:" + addSql)
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			fmt.Println("addSql err:", err)
+			return err
+		}
+	}
+	return
+}
+
+//刷新欧洲天然气指标数据
+func RefreshEdbDataFromGie(edbInfoId int, edbCode, startDate string) (err error) {
+	source := utils.DATA_SOURCE_GIE
+	o := orm.NewOrm()
+	if err != nil {
+		return
+	}
+	var suffix string
+	l := len(edbCode)
+	if strings.Contains(edbCode[l-2:], "GS") {
+		suffix = "GS"
+	} else if strings.Contains(edbCode[l-1:], "F") {
+		suffix = "F"
+	} else if strings.Contains(edbCode[l-1:], "T") {
+		suffix = "T"
+	} else if strings.Contains(edbCode[l-2:], "In") {
+		suffix = "In"
+	} else if strings.Contains(edbCode[l-3:], "Out") {
+		suffix = "Out"
+	} else if strings.Contains(edbCode[l-3:], "WGV") {
+		suffix = "WGV"
+	} else if strings.Contains(edbCode[l-2:], "IC") {
+		suffix = "IC"
+	} else if strings.Contains(edbCode[l-2:], "WC") {
+		suffix = "WC"
+	} else {
+		suffix = ""
+	}
+	edbInfoIdStr := strconv.Itoa(edbInfoId)
+	//计算数据
+	var condition string
+	var pars []interface{}
+
+	if edbCode != "" {
+		condition += " AND eic_code=? "
+		pars = append(pars, edbCode[:l-len(suffix)])
+	}
+
+	if startDate != "" {
+		condition += " AND gas_day_started_on>=? "
+		pars = append(pars, startDate)
+	}
+	eicDataList, err := GetGieDataByTradeCode(condition, pars)
+	fmt.Println("all eicDataList", len(eicDataList))
+	//获取指标所有数据
+	var existCondition string
+	var existPars []interface{}
+
+	existCondition += " AND edb_info_id=? "
+	existPars = append(existPars, edbInfoId)
+	if startDate != "" {
+		existCondition += " AND data_time>=? "
+		existPars = append(existPars, startDate)
+	}
+
+	existList, err := GetEdbDataByCondition(source, existCondition, existPars)
+	if err != nil {
+		return err
+	}
+	existMap := make(map[string]*EdbInfoSearchData)
+	for _, v := range existList {
+		existMap[v.DataTime] = v
+	}
+
+	addSql := ` INSERT INTO edb_data_gie(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
+	var isAdd bool
+	dataMap := make(map[string]interface{})
+	for _, v := range eicDataList {
+		var value string
+		if suffix == "GS" {
+			value = v.GasInStorage
+		} else if suffix == "F" {
+			value = v.Full
+		} else if suffix == "T" {
+			value = v.Trend
+		} else if suffix == "In" {
+			value = v.Injection
+		} else if suffix == "Out" {
+			value = v.Withdrawal
+		} else if suffix == "WGV" {
+			value = v.WorkingGasVolume
+		} else if suffix == "IC" {
+			value = v.InjectionCapacity
+		} else if suffix == "WC" {
+			value = v.WithdrawalCapacity
+		}
+		item := v
+		itemValue := value
+		if findItem, ok := existMap[v.GasDayStartedOn]; !ok {
+			eDate := item.GasDayStartedOn
+			sValue := itemValue
+			if sValue != "" {
+				dataTime, err := time.Parse(utils.FormatDate, eDate)
+				if err != nil {
+					return err
+				}
+				timestamp := dataTime.UnixNano() / 1e6
+				timeStr := fmt.Sprintf("%d", timestamp)
+				saveValue := sValue
+
+				if _, ok := dataMap[eDate]; !ok {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				}
+			}
+		} else {
+			if findItem != nil && utils.SubFloatToString(findItem.Value, 30) != itemValue {
+				err = ModifyEdbDataById(source, findItem.EdbDataId, itemValue)
+				if err != nil {
+					return err
+				}
+			}
+		}
+		dataMap[v.GasDayStartedOn] = v.GasDayStartedOn
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}

+ 231 - 0
models/base_from_shfe.go

@@ -0,0 +1,231 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_edb_lib/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type BaseFromTradeShfeIndex struct {
+	BaseFromTradeShfeIndexId int `orm:"column(base_from_trade_ine_index_id);pk"`
+	Rank                     int
+	DealShortName            string
+	DealName                 string
+	DealCode                 string
+	DealValue                string
+	DealChange               int
+	BuyShortName             string
+	BuyName                  string
+	BuyCode                  string
+	BuyValue                 string
+	BuyChange                int
+	SoldShortName            string
+	SoldName                 string
+	SoldCode                 string
+	SoldValue                string
+	SoldChange               int
+	Frequency                string
+	ClassifyName             string
+	ClassifyType             string
+	CreateTime               time.Time
+	ModifyTime               time.Time
+	DataTime                 string
+}
+
+func GetBaseFromShfeDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeShfeIndex, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM base_from_trade_ine_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+type BaseFromShfeDataSimple struct {
+	Id        int `orm:"column(base_from_trade_ine_index_id);pk"`
+	DealCode  string
+	BuyCode   string
+	SoldCode  string
+	DataTime  string
+	DealValue string
+	BuyValue  string
+	SoldValue string
+}
+
+func GetShfeDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromShfeDataSimple, err error) {
+	sql := ` SELECT * FROM base_from_trade_ine_index WHERE 1=1 `
+	o := orm.NewOrm()
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+//新增上期能源指标数据
+func AddEdbDataFromShfe(edbCode string) (err error) {
+	var suffix string
+	if strings.Contains(edbCode, "deal") {
+		suffix = "deal"
+	} else if strings.Contains(edbCode, "buy") {
+		suffix = "buy"
+	} else if strings.Contains(edbCode, "sold") {
+		suffix = "sold"
+	}
+	o := orm.NewOrm()
+	ineBaseDataAll, err := GetBaseFromShfeDataAllByIndexCode(edbCode, suffix)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
+
+	var isAdd bool
+	addSql := ` INSERT INTO edb_data_ine(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	existMap := make(map[string]string)
+
+	for _, sv := range ineBaseDataAll {
+		eDate := sv.DataTime
+		dataTime, err := time.Parse(utils.FormatDate, eDate)
+		if err != nil {
+			fmt.Println("time.Parse Err:" + eDate)
+			return err
+		}
+		timestamp := dataTime.UnixNano() / 1e6
+		timeStr := fmt.Sprintf("%d", timestamp)
+		if _, ok := existMap[eDate]; !ok {
+			if suffix == "deal" {
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.DealValue)
+			} else if suffix == "buy" {
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.BuyValue)
+			} else {
+				addSql += GetAddSql("0", edbCode, eDate, timeStr, sv.SoldValue)
+			}
+			isAdd = true
+		}
+		if suffix == "deal" {
+			existMap[eDate] = sv.DealValue
+		} else if suffix == "buy" {
+			existMap[eDate] = sv.BuyValue
+		} else {
+			existMap[eDate] = sv.SoldValue
+		}
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		utils.FileLog.Info("addSql:" + addSql)
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+//刷新上期能源指标数据
+func RefreshEdbDataFromShfe(edbInfoId int, edbCode, startDate string) (err error) {
+	source := utils.DATA_SOURCE_SHFE
+	o := orm.NewOrm()
+	if err != nil {
+		return
+	}
+	var suffix string
+	if strings.Contains(edbCode, "deal") {
+		suffix = "deal"
+	} else if strings.Contains(edbCode, "buy") {
+		suffix = "buy"
+	} else if strings.Contains(edbCode, "sold") {
+		suffix = "sold"
+	}
+	edbInfoIdStr := strconv.Itoa(edbInfoId)
+	//计算数据
+	var condition string
+	var pars []interface{}
+
+	if edbCode != "" {
+		if suffix == "deal" {
+			condition += " AND deal_code=? "
+		} else if suffix == "buy" {
+			condition += " AND buy_code=? "
+		} else {
+			condition += " AND sold_code=? "
+		}
+		pars = append(pars, edbCode)
+	}
+
+	if startDate != "" {
+		condition += " AND data_time>=? "
+		pars = append(pars, startDate)
+	}
+
+	glDataList, err := GetShfeDataByTradeCode(condition, pars)
+
+	//获取指标所有数据
+	var existCondition string
+	var existPars []interface{}
+
+	existCondition += " AND edb_info_id=? "
+	existPars = append(existPars, edbInfoId)
+	if startDate != "" {
+		existCondition += " AND data_time>=? "
+		existPars = append(existPars, startDate)
+	}
+
+	existList, err := GetEdbDataByCondition(source, existCondition, existPars)
+	if err != nil {
+		return err
+	}
+	existMap := make(map[string]*EdbInfoSearchData)
+	for _, v := range existList {
+		existMap[v.DataTime] = v
+	}
+
+	addSql := ` INSERT INTO edb_data_ine(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
+	var isAdd bool
+	for _, v := range glDataList {
+		var value string
+		if suffix == "deal" {
+			value = v.DealValue
+		} else if suffix == "buy" {
+			value = v.BuyValue
+		} else {
+			value = v.SoldValue
+		}
+		item := v
+		itemValue := value
+		if _, ok := existMap[v.DataTime]; !ok {
+			eDate := item.DataTime
+			sValue := itemValue
+			if sValue != "" {
+				dataTime, err := time.Parse(utils.FormatDate, eDate)
+				if err != nil {
+					return err
+				}
+				timestamp := dataTime.UnixNano() / 1e6
+				timeStr := fmt.Sprintf("%d", timestamp)
+				saveValue := sValue
+
+				if findItem, ok := existMap[eDate]; !ok {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				} else {
+					if findItem != nil && utils.SubFloatToString(findItem.Value, 30) != saveValue {
+						err = ModifyEdbDataById(source, findItem.EdbDataId, saveValue)
+						if err != nil {
+							return err
+						}
+					}
+				}
+			}
+		}
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}

+ 36 - 0
routers/commentsRouter_controllers.go

@@ -70,6 +70,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:GieController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:GieController"],
+        beego.ControllerComments{
+            Method: "Add",
+            Router: "/add",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:GieController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:GieController"],
+        beego.ControllerComments{
+            Method: "Refresh",
+            Router: "/refresh",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:LtController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:LtController"],
         beego.ControllerComments{
             Method: "Add",
@@ -178,6 +196,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:ShfeController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:ShfeController"],
+        beego.ControllerComments{
+            Method: "Add",
+            Router: "/add",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:ShfeController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:ShfeController"],
+        beego.ControllerComments{
+            Method: "Refresh",
+            Router: "/refresh",
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:SmmController"] = append(beego.GlobalControllerRouter["hongze/hongze_edb_lib/controllers:SmmController"],
         beego.ControllerComments{
             Method: "Add",

+ 10 - 0
routers/router.go

@@ -80,6 +80,16 @@ func init() {
 				&controllers.CffexController{},
 			),
 		),
+		beego.NSNamespace("/shfe",
+			beego.NSInclude(
+				&controllers.ShfeController{},
+			),
+		),
+		beego.NSNamespace("/gie",
+			beego.NSInclude(
+				&controllers.GieController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }

+ 230 - 2
swagger/swagger.json

@@ -74,6 +74,108 @@
                 }
             }
         },
+        "/cffex/add": {
+            "post": {
+                "tags": [
+                    "cffex"
+                ],
+                "description": "新增中金所指标接口",
+                "operationId": "CffexController.新增中金所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.AddEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/cffex/refresh": {
+            "post": {
+                "tags": [
+                    "cffex"
+                ],
+                "description": "刷新中金所指标接口",
+                "operationId": "CffexController.刷新中金所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.RefreshEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/dl/add": {
+            "post": {
+                "tags": [
+                    "dl"
+                ],
+                "description": "新增大商所指标接口",
+                "operationId": "DlController.新增大商所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.AddEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/dl/refresh": {
+            "post": {
+                "tags": [
+                    "dl"
+                ],
+                "description": "刷新大商所指标接口",
+                "operationId": "DlController.刷新大商所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.RefreshEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/gie/add": {
+            "post": {
+                "tags": [
+                    "gie"
+                ],
+                "description": "新增欧洲天然气指标接口",
+                "operationId": "GieController.新增欧洲天然气指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.AddEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/gie/refresh": {
+            "post": {
+                "tags": [
+                    "gie"
+                ],
+                "description": "刷新欧洲天然气指标接口",
+                "operationId": "GieController.刷新欧洲天然气指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.RefreshEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
         "/lt/add": {
             "post": {
                 "tags": [
@@ -244,6 +346,74 @@
                 }
             }
         },
+        "/sh/add": {
+            "post": {
+                "tags": [
+                    "sh"
+                ],
+                "description": "新增上期所指标接口",
+                "operationId": "ShController.新增上期所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.AddEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/sh/refresh": {
+            "post": {
+                "tags": [
+                    "sh"
+                ],
+                "description": "刷新上期所指标接口",
+                "operationId": "ShController.刷新上期所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.RefreshEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/shfe/add": {
+            "post": {
+                "tags": [
+                    "shfe"
+                ],
+                "description": "新增上期能源指标接口",
+                "operationId": "ShfeController.新增上期能源指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.AddEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/shfe/refresh": {
+            "post": {
+                "tags": [
+                    "shfe"
+                ],
+                "description": "刷新上期能源指标接口",
+                "operationId": "ShfeController.刷新上期能源指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.RefreshEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
         "/smm/add": {
             "post": {
                 "tags": [
@@ -345,10 +515,44 @@
                     }
                 }
             }
+        },
+        "/zz/add": {
+            "post": {
+                "tags": [
+                    "zz"
+                ],
+                "description": "新增郑商所指标接口",
+                "operationId": "ZzController.新增郑商所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.AddEdbInfoReq"
+                        }
+                    }
+                }
+            }
+        },
+        "/zz/refresh": {
+            "post": {
+                "tags": [
+                    "zz"
+                ],
+                "description": "刷新郑商所指标接口",
+                "operationId": "ZzController.刷新郑商所指标接口",
+                "responses": {
+                    "200": {
+                        "description": "",
+                        "schema": {
+                            "$ref": "#/definitions/models.RefreshEdbInfoReq"
+                        }
+                    }
+                }
+            }
         }
     },
     "definitions": {
-        "10348.0xc00052c870.false": {
+        "10659.0xc00059e9f0.false": {
             "title": "false",
             "type": "object"
         },
@@ -392,7 +596,7 @@
                 "EdbInfoIdArr": {
                     "type": "array",
                     "items": {
-                        "$ref": "#/definitions/10348.0xc00052c870.false"
+                        "$ref": "#/definitions/10659.0xc00059e9f0.false"
                     }
                 },
                 "EdbName": {
@@ -492,6 +696,30 @@
         {
             "name": "calculate",
             "description": "CalculateController 计算指标\n"
+        },
+        {
+            "name": "zz",
+            "description": "郑商所\n"
+        },
+        {
+            "name": "dl",
+            "description": "大商所\n"
+        },
+        {
+            "name": "sh",
+            "description": "上期所\n"
+        },
+        {
+            "name": "cffex",
+            "description": "中金所\n"
+        },
+        {
+            "name": "shfe",
+            "description": "上期能源\n"
+        },
+        {
+            "name": "gie",
+            "description": "欧洲天然气\n"
         }
     ]
 }

+ 152 - 2
swagger/swagger.yml

@@ -49,6 +49,72 @@ paths:
           description: ""
           schema:
             $ref: '#/definitions/models.RefreshEdbInfoReq'
+  /cffex/add:
+    post:
+      tags:
+      - cffex
+      description: 新增中金所指标接口
+      operationId: CffexController.新增中金所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.AddEdbInfoReq'
+  /cffex/refresh:
+    post:
+      tags:
+      - cffex
+      description: 刷新中金所指标接口
+      operationId: CffexController.刷新中金所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.RefreshEdbInfoReq'
+  /dl/add:
+    post:
+      tags:
+      - dl
+      description: 新增大商所指标接口
+      operationId: DlController.新增大商所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.AddEdbInfoReq'
+  /dl/refresh:
+    post:
+      tags:
+      - dl
+      description: 刷新大商所指标接口
+      operationId: DlController.刷新大商所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.RefreshEdbInfoReq'
+  /gie/add:
+    post:
+      tags:
+      - gie
+      description: 新增欧洲天然气指标接口
+      operationId: GieController.新增欧洲天然气指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.AddEdbInfoReq'
+  /gie/refresh:
+    post:
+      tags:
+      - gie
+      description: 刷新欧洲天然气指标接口
+      operationId: GieController.刷新欧洲天然气指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.RefreshEdbInfoReq'
   /lt/add:
     post:
       tags:
@@ -159,6 +225,50 @@ paths:
           description: ""
           schema:
             $ref: '#/definitions/models.RefreshEdbInfoReq'
+  /sh/add:
+    post:
+      tags:
+      - sh
+      description: 新增上期所指标接口
+      operationId: ShController.新增上期所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.AddEdbInfoReq'
+  /sh/refresh:
+    post:
+      tags:
+      - sh
+      description: 刷新上期所指标接口
+      operationId: ShController.刷新上期所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.RefreshEdbInfoReq'
+  /shfe/add:
+    post:
+      tags:
+      - shfe
+      description: 新增上期能源指标接口
+      operationId: ShfeController.新增上期能源指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.AddEdbInfoReq'
+  /shfe/refresh:
+    post:
+      tags:
+      - shfe
+      description: 刷新上期能源指标接口
+      operationId: ShfeController.刷新上期能源指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.RefreshEdbInfoReq'
   /smm/add:
     post:
       tags:
@@ -225,8 +335,30 @@ paths:
           description: ""
           schema:
             $ref: '#/definitions/models.RefreshEdbInfoReq'
+  /zz/add:
+    post:
+      tags:
+      - zz
+      description: 新增郑商所指标接口
+      operationId: ZzController.新增郑商所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.AddEdbInfoReq'
+  /zz/refresh:
+    post:
+      tags:
+      - zz
+      description: 刷新郑商所指标接口
+      operationId: ZzController.刷新郑商所指标接口
+      responses:
+        "200":
+          description: ""
+          schema:
+            $ref: '#/definitions/models.RefreshEdbInfoReq'
 definitions:
-  10348.0xc00052c870.false:
+  10659.0xc00059e9f0.false:
     title: "false"
     type: object
   models.AddEdbInfoReq:
@@ -261,7 +393,7 @@ definitions:
       EdbInfoIdArr:
         type: array
         items:
-          $ref: '#/definitions/10348.0xc00052c870.false'
+          $ref: '#/definitions/10659.0xc00059e9f0.false'
       EdbName:
         description: 指标名称
         type: string
@@ -334,3 +466,21 @@ tags:
 - name: calculate
   description: |
     CalculateController 计算指标
+- name: zz
+  description: |
+    郑商所
+- name: dl
+  description: |
+    大商所
+- name: sh
+  description: |
+    上期所
+- name: cffex
+  description: |
+    中金所
+- name: shfe
+  description: |
+    上期能源
+- name: gie
+  description: |
+    欧洲天然气