瀏覽代碼

Merge branch 'edb_data/v24' into debug

Roc 3 年之前
父節點
當前提交
413e009fde

+ 1 - 1
models/company_product.go

@@ -37,7 +37,7 @@ func CompanyFreeze(companyId, productId int) (companyReportPermissionList []*Com
 	freezeEndDate := time.Now().AddDate(0, 3, 0).Format(utils.FormatDate)
 
 	//客户产品 状态 变更
-	sql := `UPDATE company_product SET status='冻结',freeze_time=NOW(),modify_time=NOW(),start_date=?,end_date=?,freeze_start_date=?,freeze_end_date=? WHERE company_id=? AND product_id=? `
+	sql := `UPDATE company_product SET status='冻结',is_suspend=0,freeze_time=NOW(),modify_time=NOW(),start_date=?,end_date=?,freeze_start_date=?,freeze_end_date=? WHERE company_id=? AND product_id=? `
 	_, err = o.Raw(sql, freezeStartDate, freezeEndDate, freezeStartDate, freezeEndDate, companyId, productId).Exec()
 	if err != nil {
 		return

+ 56 - 0
models/data_manage/chart_info.go

@@ -0,0 +1,56 @@
+package data_manage
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type ChartInfo struct {
+	ChartInfoId     int    `orm:"column(chart_info_id);pk"`
+	ChartName       string `description:"来源名称"`
+	ChartClassifyId int    `description:"图表分类id"`
+	SysUserId       int
+	SysUserRealName string
+	UniqueCode      string `description:"图表唯一编码"`
+	CreateTime      time.Time
+	ModifyTime      time.Time
+	DateType        int    `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
+	StartDate       string `description:"自定义开始日期"`
+	EndDate         string `description:"自定义结束日期"`
+	IsSetName       int    `description:"设置名称"`
+	EdbInfoIds      string `description:"指标id"`
+	ChartType       int    `description:"生成样式:1:曲线图,2:季节性图"`
+	Calendar        string `description:"公历/农历"`
+	SeasonStartDate string `description:"季节性图开始日期"`
+	SeasonEndDate   string `description:"季节性图开始日期"`
+	ChartImage      string `description:"图表图片"`
+	Sort            int    `description:"排序字段,数字越小越排前面"`
+	EdbEndDate      string `description:"指标最后更新日期"`
+}
+
+func GetAllChartInfo() (list []*ChartInfo, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT * FROM chart_info  `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}
+
+func GetChartInfoEdbEndDate() (list []*ChartInfo, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT a.*,max(c.end_date) AS edb_end_date FROM  chart_info  AS a
+			INNER JOIN chart_edb_mapping AS b ON a.chart_info_id=b.chart_info_id
+			INNER JOIN edb_info AS c ON b.edb_info_id=c.edb_info_id
+			GROUP BY a.chart_info_id  `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}
+
+func ModifyChartInfoEdbEndDate(chartInfoId int, edbEndDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` UPDATE chart_info SET edb_end_date=? WHERE chart_info_id=? `
+	_, err = o.Raw(sql, edbEndDate, chartInfoId).Exec()
+	return
+}

+ 20 - 2
models/data_manage/edb_data_base.go

@@ -41,6 +41,24 @@ func GetEdbDataTableName(source int) (tableName string) {
 		tableName = "edb_data_calculate_bp"
 	case utils.DATA_SOURCE_GL:
 		tableName = "edb_data_gl"
+	case utils.DATA_SOURCE_ZZ:
+		tableName = "edb_data_zz"
+	case utils.DATA_SOURCE_DL:
+		tableName = "edb_data_dl"
+	case utils.DATA_SOURCE_SH:
+		tableName = "edb_data_sh"
+	case utils.DATA_SOURCE_CFFEX:
+		tableName = "edb_data_cffex"
+	case utils.DATA_SOURCE_SHFE:
+		tableName = "edb_data_ine"
+	case utils.DATA_SOURCE_GIE:
+		tableName = "edb_data_gie"
+	case utils.DATA_SOURCE_CALCULATE_ZJPJ:
+		tableName = "edb_data_calculate_zjpj"
+	case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT:
+		tableName = "edb_data_calculate_time_shift"
+	case utils.DATA_SOURCE_CALCULATE_LJZTBPJ:
+		tableName = "edb_data_calculate_ljztbpj"
 	default:
 		tableName = ""
 		errors.New("无效的渠道:" + strconv.Itoa(source))
@@ -75,7 +93,7 @@ func GetEdbInfoCalculateTableName(source int) (tableName string) {
 	return
 }
 
-func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr,value string) (addSql string) {
+func GetAddSql(edbInfoId, edbCode, dataTime, timestampStr, value string) (addSql string) {
 	nowStr := time.Now().Format(utils.FormatDateTime)
 	addSql += "("
 	addSql += edbInfoId + "," + "'" + edbCode + "'" + "," + "'" + dataTime + "'" + "," + value + "," + "'" + nowStr + "'" +
@@ -105,4 +123,4 @@ type EdbDataBase struct {
 	CreateTime    time.Time
 	ModifyTime    time.Time
 	DataTimestamp int64
-}
+}

+ 1 - 1
models/data_manage/edb_data_calculate.go

@@ -51,7 +51,7 @@ type EdbInfoCalculateDetail struct {
 func GetEdbInfoCalculateDetail(edbInfoId int) (list []*EdbInfoCalculateDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? ORDER BY sort ASC `
 	_, err = o.Raw(sql, edbInfoId).QueryRows(&list)

+ 28 - 0
models/data_manage/edb_data_calculate_ljztbpj.go

@@ -0,0 +1,28 @@
+package data_manage
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+// EdbDataCalculateLjztbpj 累计值同比拼接数据结构体
+type EdbDataCalculateLjztbpj struct {
+	EdbDataId     int `orm:"column(edb_data_id);pk"`
+	EdbInfoId     int
+	EdbCode       string
+	DataTime      string
+	Value         float64
+	Status        int
+	CreateTime    time.Time
+	ModifyTime    time.Time
+	DataTimestamp int64
+}
+
+// GetAllEdbDataCalculateLjztbpjByEdbInfoId 根据指标id获取全部的数据
+func GetAllEdbDataCalculateLjztbpjByEdbInfoId(edbInfoId int) (items []*EdbDataCalculateLjztbpj, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT * FROM edb_data_calculate_ljztbpj WHERE edb_info_id=? ORDER BY data_time DESC `
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+	return
+}

+ 261 - 0
models/data_manage/edb_data_calculate_time_shift.go

@@ -0,0 +1,261 @@
+package data_manage
+
+import (
+	"fmt"
+	"github.com/shopspring/decimal"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"strconv"
+	"strings"
+	"time"
+)
+
+//时间移位
+
+type EdbInfoCalculateMove struct {
+	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
+	EdbInfoId            int       `description:"指标id"`
+	EdbCode              string    `description:"指标编码"`
+	FromEdbInfoId        int       `description:"计算指标id"`
+	FromEdbCode          string    `description:"计算指标编码"`
+	FromEdbName          string    `description:"计算指标名称"`
+	FromSource           int       `description:"计算指标来源"`
+	FromSourceName       string    `description:"计算指标来源名称"`
+	FromTag              string    `description:"来源指标标签"`
+	Sort                 int       `description:"计算指标名称排序"`
+	CreateTime           time.Time `description:"创建时间"`
+	ModifyTime           time.Time `description:"修改时间"`
+}
+
+//变频
+func RefreshCalculateTimeShift(edbInfoId, formulaInt, moveType int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate, moveFrequency string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+
+	if err != nil {
+		return
+	}
+	edbInfoIdStr := strconv.Itoa(edbInfoId)
+	//计算数据
+
+	//计算数据
+	var condition string
+	var pars []interface{}
+	condition += " AND edb_info_id=? "
+	pars = append(pars, fromEdbInfo.EdbInfoId)
+
+	if startDate != "" {
+		condition += " AND data_time>=? "
+		pars = append(pars, startDate)
+	}
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	var shiftDay int
+	switch moveFrequency {
+	case "天":
+		shiftDay = formulaInt
+	case "周":
+		shiftDay = formulaInt * 7
+	case "月":
+		shiftDay = formulaInt * 30
+	case "季":
+		shiftDay = formulaInt * 90
+	case "年":
+		shiftDay = formulaInt * 365
+	default:
+		shiftDay = formulaInt
+	}
+	if moveType == 2 {
+		shiftDay = -shiftDay
+	}
+	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
+	if err != nil {
+		return err
+	}
+	existMap := make(map[string]string)
+	dataLen := len(dataList)
+	addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	for i := 0; i < dataLen; i++ {
+		//当期
+		currentItem := dataList[i]
+		existKey := edbCode + currentItem.DataTime
+		if _, ok := existMap[existKey]; !ok {
+			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
+			newDate := currentDate.AddDate(0, 0, -shiftDay)
+			timestamp := newDate.UnixNano() / 1e6
+			timestampStr := fmt.Sprintf("%d", timestamp)
+			valStr := decimal.NewFromFloat(currentItem.Value).String()
+			addSql += GetAddSql(edbInfoIdStr, edbCode, newDate.Format(utils.FormatDate), timestampStr, valStr)
+		}
+		existMap[existKey] = currentItem.DataTime
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+type EdbInfoCalculateTimeShiftDetail struct {
+	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
+	EdbInfoId            int       `description:"指标id"`
+	EdbCode              string    `description:"指标编码"`
+	FromEdbInfoId        int       `description:"计算指标id"`
+	FromEdbCode          string    `description:"计算指标编码"`
+	FromEdbName          string    `description:"计算指标名称"`
+	FromSource           int       `description:"计算指标来源"`
+	FromSourceName       string    `description:"计算指标来源名称"`
+	FromTag              string    `description:"来源指标标签"`
+	Sort                 int       `description:"计算指标名称排序"`
+	CreateTime           time.Time `description:"创建时间"`
+	ModifyTime           time.Time `description:"修改时间"`
+	StartDate            string    `description:"开始日期"`
+	EndDate              string    `description:"结束日期"`
+}
+
+func GetEdbInfoCalculateTimeShiftDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
+			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
+			WHERE a.edb_info_id=? `
+	err = o.Raw(sql, edbInfoId).QueryRow(&item)
+	return
+}
+
+//刷新所有变频数据
+func RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, moveType int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate, moveFrequency string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+
+	if err != nil {
+		return
+	}
+	edbInfoIdStr := strconv.Itoa(edbInfoId)
+	//计算数据
+
+	//计算数据
+	var condition string
+	var pars []interface{}
+	condition += " AND edb_info_id=? "
+	pars = append(pars, fromEdbInfo.EdbInfoId)
+
+	if startDate != "" {
+		condition += " AND data_time>=? "
+		pars = append(pars, startDate)
+	}
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	var shiftDay int
+	switch moveFrequency {
+	case "天":
+		shiftDay = formulaInt
+	case "周":
+		shiftDay = formulaInt * 7
+	case "月":
+		shiftDay = formulaInt * 30
+	case "季":
+		shiftDay = formulaInt * 90
+	case "年":
+		shiftDay = formulaInt * 365
+	default:
+		shiftDay = formulaInt
+	}
+
+	if moveType == 2 {
+		shiftDay = -shiftDay
+	}
+
+	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
+	if err != nil {
+		return err
+	}
+	var dateArr []string
+	dataMap := make(map[string]*EdbInfoSearchData)
+	for _, v := range dataList {
+		dateArr = append(dateArr, v.DataTime)
+		dataMap[v.DataTime] = v
+	}
+	fmt.Println("source:", source)
+	//获取指标所有数据
+	existDataList := make([]*EdbDataBase, 0)
+	dataTableName := GetEdbDataTableName(source)
+	fmt.Println("dataTableName:", dataTableName)
+	sql := `SELECT * FROM %s WHERE edb_info_id=? `
+	sql = fmt.Sprintf(sql, dataTableName)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&existDataList)
+	if err != nil {
+		return err
+	}
+	existDataMap := make(map[string]string)
+	for _, v := range existDataList {
+		existDataMap[v.DataTime] = v.Value
+	}
+	fmt.Println("existDataMap:", existDataMap)
+	addSql := ` INSERT INTO edb_data_calculate_bp(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+
+	existMap := make(map[string]string)
+	dataLen := len(dataList)
+	for i := 0; i < dataLen; i++ {
+		//当期
+		currentItem := dataList[i]
+		existKey := edbCode + currentItem.DataTime
+		if _, ok := existMap[existKey]; !ok {
+			currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
+			newDate := currentDate.AddDate(0, 0, shiftDay)
+
+			timestamp := newDate.UnixNano() / 1e6
+			timestampStr := fmt.Sprintf("%d", timestamp)
+			valStr := decimal.NewFromFloat(currentItem.Value).String()
+			if existVal, ok := existDataMap[currentItem.DataTime]; !ok {
+				addSql += GetAddSql(edbInfoIdStr, edbCode, newDate.Format(utils.FormatDate), timestampStr, valStr)
+			} else {
+				if existVal != valStr {
+					sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+					sql = fmt.Sprintf(sql, dataTableName)
+					_, err = o.Raw(sql, valStr, edbInfoId, newDate.Format(utils.FormatDate)).Exec()
+					if err != nil {
+						return err
+					}
+				}
+			}
+		}
+		existMap[existKey] = currentItem.DataTime
+	}
+
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}

+ 28 - 0
models/data_manage/edb_data_calculate_zjpj.go

@@ -0,0 +1,28 @@
+package data_manage
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+// EdbDataCalculateZjpj 直接拼接数据结构体
+type EdbDataCalculateZjpj struct {
+	EdbDataId     int `orm:"column(edb_data_id);pk"`
+	EdbInfoId     int
+	EdbCode       string
+	DataTime      string
+	Value         float64
+	Status        int
+	CreateTime    time.Time
+	ModifyTime    time.Time
+	DataTimestamp int64
+}
+
+// GetAllEdbDataCalculateZjpjByEdbInfoId 根据指标id获取全部的数据
+func GetAllEdbDataCalculateZjpjByEdbInfoId(edbInfoId int) (items []*EdbDataCalculateZjpj, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT * FROM edb_data_calculate_zjpj WHERE edb_info_id=? ORDER BY data_time DESC `
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+	return
+}

+ 341 - 0
models/data_manage/edb_data_cffex.go

@@ -0,0 +1,341 @@
+package data_manage
+
+import (
+	"fmt"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type CffexData struct {
+	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
+	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
+}
+
+type BaseFromCffexDataSimple struct {
+	Id        int `orm:"column(base_from_trade_cffex_index_id);pk"`
+	DealCode  string
+	BuyCode   string
+	SoldCode  string
+	DataTime  string
+	DealValue string
+	BuyValue  string
+	SoldValue string
+}
+
+type BaseInfoFromCffex struct {
+	DealName string
+	BuyName  string
+	SoldName string
+}
+
+type BaseFromTradeCFFEXIndex struct {
+	BaseFromTradeCffexIndexId int `orm:"column(base_from_trade_cffex_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 GetEdbDataCffexMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_cffex WHERE edb_code=? `
+	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
+	return
+}
+
+
+// RefreshEdbDataByCffex 刷新中金所指标数据
+func RefreshEdbDataByCffex(edbInfoId int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetCffexDataByTradeCode(condition, pars)
+
+	addSql := ` INSERT INTO edb_data_cffex(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 {
+			count, err := GetEdbDataCffexByCodeAndDate(edbCode, v.DataTime)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			if count <= 0 {
+				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)
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
+					isAdd = true
+				}
+			} else {
+				err = ModifyEdbDataCffex(int64(edbInfoId), v.DataTime, value)
+				if err != nil {
+					return err
+				}
+			}
+		}
+		existMap[v.DataTime] = value
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// RefreshAllEdbDataByCffex 全部刷新中金所
+func RefreshAllEdbDataByCffex(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetCffexDataByTradeCode(condition, pars)
+
+	//获取指标所有数据
+	dataList := make([]*EdbDataBase, 0)
+	dataTableName := GetEdbDataTableName(source)
+	sql := `SELECT * FROM %s WHERE edb_info_id=? `
+	sql = fmt.Sprintf(sql, dataTableName)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
+	if err != nil {
+		return err
+	}
+	dataMap := make(map[string]string)
+	for _, v := range dataList {
+		dataMap[v.DataTime] = v.Value
+	}
+
+	addSql := ` INSERT INTO edb_data_cffex(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 existVal, ok := dataMap[eDate]; !ok {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				} else {
+					if existVal != saveValue {
+						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+						sql = fmt.Sprintf(sql, dataTableName)
+						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
+						if err != nil {
+							return err
+						}
+					}
+				}
+			}
+		}
+		existMap[v.DataTime] = v.DataTime
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// GetBaseInfoFromCffexByIndexCode 获取指标信息
+func GetBaseInfoFromCffexByIndexCode(indexCode, suffix string) (list []*BaseInfoFromCffex, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_cffex_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetCffexDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromCffexDataSimple, err error) {
+	sql := ` SELECT * FROM base_from_trade_cffex_index WHERE 1=1 `
+	o := orm.NewOrm()
+	o.Using("data")
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+func AddEdbDataCffexBySql(sqlStr string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	_, err = o.Raw(sqlStr).Exec()
+	return
+}
+
+func GetBaseFromCffexDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeCFFEXIndex, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_cffex_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetEdbDataCffexByCodeAndDate(edbCode string, startDate string) (count int, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT COUNT(1) AS count FROM edb_data_cffex WHERE edb_code=? AND data_time=? `
+	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
+	return
+}
+
+func ModifyEdbDataCffex(edbInfoId int64, dataTime, value string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` UPDATE edb_data_cffex SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
+	return
+}

+ 342 - 0
models/data_manage/edb_data_dl.go

@@ -0,0 +1,342 @@
+package data_manage
+
+import (
+	"fmt"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type DlData struct {
+	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
+	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
+}
+
+type BaseFromDlDataSimple struct {
+	Id        int `orm:"column(base_from_trade_dalian_index_id);pk"`
+	DealCode  string
+	BuyCode   string
+	SoldCode  string
+	DataTime  string
+	DealValue string
+	BuyValue  string
+	SoldValue string
+}
+
+type BaseInfoFromDl struct {
+	DealName string
+	BuyName  string
+	SoldName string
+}
+
+type BaseFromTradeDalianIndex struct {
+	BaseFromTradeDalianIndexId int `orm:"column(base_from_trade_dalian_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 GetEdbDataDlMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_dl WHERE edb_code=? `
+	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
+	return
+}
+
+
+// RefreshEdbDataByDl 刷新大商所指标数据
+func RefreshEdbDataByDl(edbInfoId int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetDlDataByTradeCode(condition, pars)
+
+	addSql := ` INSERT INTO edb_data_dl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 {
+			count, err := GetEdbDataDlByCodeAndDate(edbCode, v.DataTime)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			if count <= 0 {
+				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)
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
+					isAdd = true
+				}
+			} else {
+				err = ModifyEdbDataDl(int64(edbInfoId), v.DataTime, value)
+				if err != nil {
+					return err
+				}
+			}
+		}
+		existMap[v.DataTime] = value
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// RefreshAllEdbDataByDl 全部刷新大商所
+func RefreshAllEdbDataByDl(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetDlDataByTradeCode(condition, pars)
+
+	//获取指标所有数据
+	dataList := make([]*EdbDataBase, 0)
+	dataTableName := GetEdbDataTableName(source)
+	sql := `SELECT * FROM %s WHERE edb_info_id=? `
+	sql = fmt.Sprintf(sql, dataTableName)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
+	if err != nil {
+		return err
+	}
+	dataMap := make(map[string]string)
+	for _, v := range dataList {
+		dataMap[v.DataTime] = v.Value
+	}
+
+	addSql := ` INSERT INTO edb_data_dl(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 existVal, ok := dataMap[eDate]; !ok {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				} else {
+					if existVal != saveValue {
+						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+						sql = fmt.Sprintf(sql, dataTableName)
+						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
+						if err != nil {
+							return err
+						}
+					}
+				}
+			}
+		}
+		existMap[v.DataTime] = v.DataTime
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// GetBaseInfoFromDalianByIndexCode 获取指标信息
+func GetBaseInfoFromDalianByIndexCode(indexCode, suffix string) (list []*BaseInfoFromDl, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_dalian_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetDlDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromDlDataSimple, err error) {
+	sql := ` SELECT * FROM base_from_trade_dalian_index WHERE 1=1 `
+	o := orm.NewOrm()
+	o.Using("data")
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+func AddEdbDataDlBySql(sqlStr string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	_, err = o.Raw(sqlStr).Exec()
+	return
+}
+
+
+func GetBaseFromDalianDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeDalianIndex, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_dalian_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetEdbDataDlByCodeAndDate(edbCode string, startDate string) (count int, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT COUNT(1) AS count FROM edb_data_dl WHERE edb_code=? AND data_time=? `
+	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
+	return
+}
+
+func ModifyEdbDataDl(edbInfoId int64, dataTime, value string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` UPDATE edb_data_dl SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
+	return
+}

+ 340 - 0
models/data_manage/edb_data_sh.go

@@ -0,0 +1,340 @@
+package data_manage
+
+import (
+	"fmt"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type ShData struct {
+	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
+	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
+}
+
+type BaseFromShDataSimple struct {
+	Id        int `orm:"column(base_from_trade_shanghai_index_id);pk"`
+	DealCode  string
+	BuyCode   string
+	SoldCode  string
+	DataTime  string
+	DealValue string
+	BuyValue  string
+	SoldValue string
+}
+
+type BaseInfoFromSh struct {
+	DealName string
+	BuyName  string
+	SoldName string
+}
+
+type BaseFromTradeShIndex struct {
+	BaseFromTradeShIndexId int `orm:"column(base_from_trade_shanghai_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 GetEdbDataShMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_sh WHERE edb_code=? `
+	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
+	return
+}
+
+// RefreshEdbDataBySh 刷新上期所指标数据
+func RefreshEdbDataBySh(edbInfoId int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetShDataByTradeCode(condition, pars)
+
+	addSql := ` INSERT INTO edb_data_sh(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 {
+			count, err := GetEdbDataShByCodeAndDate(edbCode, v.DataTime)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			if count <= 0 {
+				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)
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
+					isAdd = true
+				}
+			} else {
+				err = ModifyEdbDataSh(int64(edbInfoId), v.DataTime, value)
+				if err != nil {
+					return err
+				}
+			}
+		}
+		existMap[v.DataTime] = value
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// RefreshAllEdbDataBySh 全部刷新上期所
+func RefreshAllEdbDataBySh(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetShDataByTradeCode(condition, pars)
+
+	//获取指标所有数据
+	dataList := make([]*EdbDataBase, 0)
+	dataTableName := GetEdbDataTableName(source)
+	sql := `SELECT * FROM %s WHERE edb_info_id=? `
+	sql = fmt.Sprintf(sql, dataTableName)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
+	if err != nil {
+		return err
+	}
+	dataMap := make(map[string]string)
+	for _, v := range dataList {
+		dataMap[v.DataTime] = v.Value
+	}
+
+	addSql := ` INSERT INTO edb_data_sh(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 existVal, ok := dataMap[eDate]; !ok {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				} else {
+					if existVal != saveValue {
+						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+						sql = fmt.Sprintf(sql, dataTableName)
+						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
+						if err != nil {
+							return err
+						}
+					}
+				}
+			}
+		}
+		existMap[v.DataTime] = v.DataTime
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// GetBaseInfoFromShByIndexCode 获取指标信息
+func GetBaseInfoFromShByIndexCode(indexCode, suffix string) (list []*BaseInfoFromSh, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_shanghai_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetShDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromShDataSimple, err error) {
+	sql := ` SELECT * FROM base_from_trade_shanghai_index WHERE 1=1 `
+	o := orm.NewOrm()
+	o.Using("data")
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+func AddEdbDataShBySql(sqlStr string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	_, err = o.Raw(sqlStr).Exec()
+	return
+}
+
+func GetBaseFromShDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeShIndex, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_shanghai_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetEdbDataShByCodeAndDate(edbCode string, startDate string) (count int, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT COUNT(1) AS count FROM edb_data_sh WHERE edb_code=? AND data_time=? `
+	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
+	return
+}
+
+func ModifyEdbDataSh(edbInfoId int64, dataTime, value string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` UPDATE edb_data_sh SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
+	return
+}

+ 343 - 0
models/data_manage/edb_data_shfe.go

@@ -0,0 +1,343 @@
+package data_manage
+
+import (
+	"fmt"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type ShfeData struct {
+	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
+	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
+}
+
+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
+}
+
+type BaseInfoFromShfe struct {
+	DealName string
+	BuyName  string
+	SoldName string
+}
+
+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 GetEdbDataShfeMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_ine WHERE edb_code=? `
+	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
+	return
+}
+
+
+// RefreshEdbDataByShfe 刷新上期能源指标数据
+func RefreshEdbDataByShfe(edbInfoId int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetShfeDataByTradeCode(condition, pars)
+
+	addSql := ` INSERT INTO edb_data_ine(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 {
+			count, err := GetEdbDataShfeByCodeAndDate(edbCode, v.DataTime)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			if count <= 0 {
+				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)
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
+					isAdd = true
+				}
+			} else {
+				err = ModifyEdbDataShfe(int64(edbInfoId), v.DataTime, value)
+				if err != nil {
+					return err
+				}
+			}
+		}
+		existMap[v.DataTime] = value
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// RefreshAllEdbDataByShfe 全部刷新上期能源
+func RefreshAllEdbDataByShfe(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetShfeDataByTradeCode(condition, pars)
+
+	//获取指标所有数据
+	dataList := make([]*EdbDataBase, 0)
+	dataTableName := GetEdbDataTableName(source)
+	sql := `SELECT * FROM %s WHERE edb_info_id=? `
+	sql = fmt.Sprintf(sql, dataTableName)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
+	if err != nil {
+		return err
+	}
+	dataMap := make(map[string]string)
+	for _, v := range dataList {
+		dataMap[v.DataTime] = v.Value
+	}
+
+	addSql := ` INSERT INTO edb_data_ine(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 existVal, ok := dataMap[eDate]; !ok {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				} else {
+					if existVal != saveValue {
+						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+						sql = fmt.Sprintf(sql, dataTableName)
+						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
+						if err != nil {
+							return err
+						}
+					}
+				}
+			}
+		}
+		existMap[v.DataTime] = v.DataTime
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// GetBaseInfoFromShfeByIndexCode 获取指标信息
+func GetBaseInfoFromShfeByIndexCode(indexCode, suffix string) (list []*BaseInfoFromShfe, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_ine_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetShfeDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromShfeDataSimple, err error) {
+	sql := ` SELECT * FROM base_from_trade_ine_index WHERE 1=1 `
+	o := orm.NewOrm()
+	o.Using("data")
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+func AddEdbDataShfeBySql(sqlStr string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	_, err = o.Raw(sqlStr).Exec()
+	return
+}
+
+
+
+func GetBaseFromShfeDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeShfeIndex, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_ine_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetEdbDataShfeByCodeAndDate(edbCode string, startDate string) (count int, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT COUNT(1) AS count FROM edb_data_ine WHERE edb_code=? AND data_time=? `
+	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
+	return
+}
+
+func ModifyEdbDataShfe(edbInfoId int64, dataTime, value string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` UPDATE edb_data_ine SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
+	return
+}

+ 343 - 0
models/data_manage/edb_data_zz.go

@@ -0,0 +1,343 @@
+package data_manage
+
+import (
+	"fmt"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type ZzData struct {
+	InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
+	DataTime   string `orm:"column(DATA_DATE)" description:"值"`
+}
+
+type BaseFromZzDataSimple struct {
+	Id        int `orm:"column(base_from_trade_zhengzhou_index_id);pk"`
+	DealCode  string
+	BuyCode   string
+	SoldCode  string
+	DataTime  string
+	DealValue string
+	BuyValue  string
+	SoldValue string
+}
+
+type BaseInfoFromZz struct {
+	DealName string
+	BuyName  string
+	SoldName string
+}
+
+type BaseFromTradeZhengzhouIndex struct {
+	BaseFromTradeZhengzhouIndexId int `orm:"column(base_from_trade_zhengzhou_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 GetEdbDataZzMaxOrMinDate(edbCode string) (minDate, maxDate string, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT MIN(data_time) AS minDate,MAX(data_time) AS maxDate FROM edb_data_zz WHERE edb_code=? `
+	err = o.Raw(sql, edbCode).QueryRow(&minDate, &maxDate)
+	return
+}
+
+
+// RefreshEdbDataByZz 刷新郑商所指标数据
+func RefreshEdbDataByZz(edbInfoId int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetZzDataByTradeCode(condition, pars)
+
+	addSql := ` INSERT INTO edb_data_zz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 {
+			count, err := GetEdbDataZzByCodeAndDate(edbCode, v.DataTime)
+			if err != nil && err.Error() != utils.ErrNoRow() {
+				return err
+			}
+			if count <= 0 {
+				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)
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, sValue)
+					isAdd = true
+				}
+			} else {
+				err = ModifyEdbDataZz(int64(edbInfoId), v.DataTime, value)
+				if err != nil {
+					return err
+				}
+			}
+		}
+		existMap[v.DataTime] = value
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// RefreshAllEdbDataByZz 全部刷新郑商所
+func RefreshAllEdbDataByZz(edbInfoId, source int, edbCode, startDate, endDate string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	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)
+	}
+
+	if endDate != "" {
+		condition += " AND data_time<=? "
+		pars = append(pars, endDate)
+	}
+
+	glDataList, err := GetZzDataByTradeCode(condition, pars)
+
+	//获取指标所有数据
+	dataList := make([]*EdbDataBase, 0)
+	dataTableName := GetEdbDataTableName(source)
+	sql := `SELECT * FROM %s WHERE edb_info_id=? `
+	sql = fmt.Sprintf(sql, dataTableName)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&dataList)
+	if err != nil {
+		return err
+	}
+	dataMap := make(map[string]string)
+	for _, v := range dataList {
+		dataMap[v.DataTime] = v.Value
+	}
+
+	addSql := ` INSERT INTO edb_data_zz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
+	var isAdd bool
+	existMap := make(map[string]string)
+	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 existVal, ok := dataMap[eDate]; !ok {
+					addSql += GetAddSql(edbInfoIdStr, edbCode, eDate, timeStr, saveValue)
+					isAdd = true
+				} else {
+					if existVal != saveValue {
+						sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+						sql = fmt.Sprintf(sql, dataTableName)
+						_, err = o.Raw(sql, sValue, edbInfoId, eDate).Exec()
+						if err != nil {
+							return err
+						}
+					}
+				}
+			}
+		}
+		existMap[v.DataTime] = v.DataTime
+	}
+	if isAdd {
+		addSql = strings.TrimRight(addSql, ",")
+		_, err = o.Raw(addSql).Exec()
+		if err != nil {
+			return err
+		}
+	}
+	return
+}
+
+// GetBaseInfoFromZhengzhouByIndexCode 获取指标信息
+func GetBaseInfoFromZhengzhouByIndexCode(indexCode, suffix string) (list []*BaseInfoFromZz, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_zhengzhou_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetZzDataByTradeCode(condition string, pars []interface{}) (item []*BaseFromZzDataSimple, err error) {
+	sql := ` SELECT * FROM base_from_trade_zhengzhou_index WHERE 1=1 `
+	o := orm.NewOrm()
+	o.Using("data")
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time DESC `
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+func AddEdbDataZzBySql(sqlStr string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	_, err = o.Raw(sqlStr).Exec()
+	return
+}
+
+
+
+func GetBaseFromZhengzhouDataAllByIndexCode(indexCode, suffix string) (list []*BaseFromTradeZhengzhouIndex, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_trade_zhengzhou_index WHERE %s_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&list)
+	return
+}
+
+func GetEdbDataZzByCodeAndDate(edbCode string, startDate string) (count int, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT COUNT(1) AS count FROM edb_data_zz WHERE edb_code=? AND data_time=? `
+	err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
+	return
+}
+
+func ModifyEdbDataZz(edbInfoId int64, dataTime, value string) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` UPDATE edb_data_zz SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
+	_, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
+	return
+}

+ 44 - 0
models/data_manage/edb_info.go

@@ -49,6 +49,11 @@ type EdbInfoSearchData struct {
 	Value    float64 `description:"数据"`
 }
 
+type EdbInfoSearchDataV1 struct {
+	DataTime string `description:"数据日期"`
+	Value    string `description:"数据"`
+}
+
 func GetEdbInfoByCondition(condition string, pars []interface{}, order int) (item []*EdbInfoList, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
@@ -127,6 +132,26 @@ func GetEdbDataListAll(condition string, pars []interface{}, source, order int)
 	return
 }
 
+func GetEdbDataListAllV1(condition string, pars []interface{}, source, order int) (item []*EdbInfoSearchDataV1, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ``
+	tableName := GetEdbDataTableName(source)
+	sql = ` SELECT * FROM %s WHERE 1=1 `
+	sql = fmt.Sprintf(sql, tableName)
+
+	if condition != "" {
+		sql += condition
+	}
+	if order == 1 {
+		sql += ` ORDER BY data_time ASC `
+	} else {
+		sql += ` ORDER BY data_time DESC `
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
 func GetEdbInfoById(edbInfoId int) (item *EdbInfo, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
@@ -155,3 +180,22 @@ func ResetEdbInfoIsUpdate() (err error) {
 	_, err = o.Raw(sql).Exec()
 	return
 }
+
+// GetEdbInfoCalculateListByCondition 获取指标关系列表
+func GetEdbInfoCalculateListByCondition(condition string, pars []interface{}) (items []*EdbInfoCalculateMapping, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	//calculateTableName := GetEdbInfoCalculateTableName(source)
+	//if calculateTableName == "" {
+	//	err = errors.New("无效的表名")
+	//	return
+	//}
+
+	sql := ` SELECT * FROM edb_info_calculate_mapping WHERE 1=1 `
+	//sql = fmt.Sprintf(sql, calculateTableName)
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 1 - 1
models/data_manage/edb_info_calculate_bp.go

@@ -157,7 +157,7 @@ type EdbInfoCalculateBpDetail struct {
 func GetEdbInfoCalculateBpDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_bp AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? `
 	err = o.Raw(sql, edbInfoId).QueryRow(&item)

+ 12 - 12
models/data_manage/edb_info_calculate_hbz.go

@@ -38,7 +38,7 @@ func HbzDiv(current, pre float64) string {
 }
 
 //刷新环比值数据
-func RefreshCalculateHbz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, startDate, endDate string) (err error) {
+func RefreshCalculateHbz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode string, formulaInt int) (err error) {
 	o := orm.NewOrm()
 	o.Using("data")
 	o.Begin()
@@ -60,14 +60,14 @@ func RefreshCalculateHbz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, s
 	condition += " AND edb_info_id=? "
 	pars = append(pars, fromEdbInfo.EdbInfoId)
 
-	if startDate != "" {
-		condition += " AND data_time>=? "
-		pars = append(pars, startDate)
-	}
-	if endDate != "" {
-		condition += " AND data_time<=? "
-		pars = append(pars, endDate)
-	}
+	//if startDate != "" {
+	//	condition += " AND data_time>=? "
+	//	pars = append(pars, startDate)
+	//}
+	//if endDate != "" {
+	//	condition += " AND data_time<=? "
+	//	pars = append(pars, endDate)
+	//}
 
 	dataList, err := GetEdbDataListAll(condition, pars, fromEdbInfo.Source, 0)
 	if err != nil {
@@ -94,7 +94,7 @@ func RefreshCalculateHbz(edbInfoId, source int, fromEdbInfo *EdbInfo, edbCode, s
 	dataLen := len(dataList)
 	fmt.Println("dataLen:", dataLen)
 	for i := 0; i < dataLen; i++ {
-		j := i + 1
+		j := i + formulaInt
 		if j < dataLen {
 			//当期
 			currentItem := dataList[i]
@@ -156,9 +156,9 @@ type EdbInfoCalculateHbzDetail struct {
 func GetEdbInfoCalculateHbzDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_hbz AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? `
 	err = o.Raw(sql, edbInfoId).QueryRow(&item)
 	return
-}
+}

+ 1 - 1
models/data_manage/edb_info_calculate_hcz.go

@@ -155,7 +155,7 @@ type EdbInfoCalculateHczDetail struct {
 func GetEdbInfoCalculateHczDetail(edbInfoId int) (item *EdbInfoCalculateHczDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_hcz AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? `
 	err = o.Raw(sql, edbInfoId).QueryRow(&item)

+ 287 - 0
models/data_manage/edb_info_calculate_ljztbpj.go

@@ -0,0 +1,287 @@
+package data_manage
+
+import (
+	"errors"
+	"fmt"
+	"github.com/shopspring/decimal"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"sort"
+	"strings"
+	"time"
+)
+
+type EdbInfoCalculateLjztbpjDetail struct {
+	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
+	EdbInfoId            int       `description:"指标id"`
+	EdbCode              string    `description:"指标编码"`
+	FromEdbInfoId        int       `description:"计算指标id"`
+	FromEdbCode          string    `description:"计算指标编码"`
+	FromEdbName          string    `description:"计算指标名称"`
+	FromSource           int       `description:"计算指标来源"`
+	FromSourceName       string    `description:"计算指标来源名称"`
+	FromTag              string    `description:"来源指标标签"`
+	Sort                 int       `description:"计算指标名称排序"`
+	CreateTime           time.Time `description:"创建时间"`
+	ModifyTime           time.Time `description:"修改时间"`
+	StartDate            string    `description:"开始日期"`
+	EndDate              string    `description:"结束日期"`
+}
+
+// RefreshAllCalculateLjztbpj 刷新所有 累计值同比拼接 数据
+func RefreshAllCalculateLjztbpj(edbInfo *EdbInfoList) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+
+	//查询当前指标现有的数据
+	var condition string
+	var pars []interface{}
+	condition += " AND edb_info_id=? "
+	pars = append(pars, edbInfo.EdbInfoId)
+
+	//所有的数据
+	dataList, err := GetAllEdbDataCalculateLjztbpjByEdbInfoId(edbInfo.EdbInfoId)
+	if err != nil {
+		return err
+	}
+
+	//待拼接指标map
+	pjDataMap := make(map[string]float64)     //需要入库的数据
+	nowEdbDataMap := make(map[string]float64) //当前指标的数据(已经在库里了,不需要重新)
+	//拼接指标的日期切片数据
+	pjEdbDataTimeList := make([]string, 0)
+
+	dataMap := make(map[string]*EdbDataCalculateLjztbpj)
+	for _, v := range dataList {
+		pjEdbDataTimeList = append(pjEdbDataTimeList, v.DataTime)
+		dataMap[v.DataTime] = v
+		nowEdbDataMap[v.DataTime] = v.Value
+	}
+
+	//查询关联指标信息
+	var existCondition string
+	var existPars []interface{}
+	existCondition += " AND edb_info_id=? "
+	existPars = append(existPars, edbInfo.EdbInfoId)
+	existList, err := GetEdbInfoCalculateListByCondition(existCondition, existPars)
+	if err != nil {
+		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
+		return
+	}
+
+	var existItemA, existItemB *EdbInfoCalculateMapping
+	for _, existItem := range existList {
+		if existItem.FromTag == "A" {
+			existItemA = existItem
+		} else if existItem.FromTag == "B" {
+			existItemB = existItem
+		}
+	}
+	// 原数据开始计算日期
+	startCalculationDate, _ := time.ParseInLocation(utils.FormatDate, edbInfo.CalculateFormula, time.Local)
+
+	//待拼接指标
+	{
+		var condition string
+		var pars []interface{}
+
+		condition += " AND data_time <= ? AND edb_info_id=? "
+		pars = append(pars, startCalculationDate, existItemA.FromEdbInfoId)
+
+		//第一个指标的数据列表
+		firstDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemA.FromSource, 0)
+		if tmpErr != nil {
+			return tmpErr
+		}
+
+		for _, v := range firstDataList {
+			//时间戳
+			if edbData, ok := dataMap[v.DataTime]; ok {
+				if edbData.Value != v.Value {
+					//更新指标数据
+					edbData.Value = v.Value
+					o.Update(edbData, "Value")
+
+					//将新的数据存入已入库指标map里面,以便后续计算
+					nowEdbDataMap[edbData.DataTime] = v.Value
+				}
+			}
+		}
+	}
+
+	//同比值指标map
+	tbzEdbDataMap := make(map[string]float64)
+
+	//同比值日期切片列表
+	tbzEdbDataTimeList := make([]string, 0)
+
+	//同比值指标
+	{
+		var condition string
+		var pars []interface{}
+
+		condition += " AND data_time > ? AND edb_info_id = ? "
+		pars = append(pars, startCalculationDate, existItemB.FromEdbInfoId)
+
+		//第二个指标的数据列表
+		secondDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemB.FromSource, 0)
+		if tmpErr != nil {
+			return tmpErr
+		}
+
+		for _, v := range secondDataList {
+			tbzEdbDataMap[v.DataTime] = v.Value
+			tbzEdbDataTimeList = append(tbzEdbDataTimeList, v.DataTime)
+		}
+	}
+
+	sort.Strings(tbzEdbDataTimeList)
+
+	// 遍历现有的数据,判断拼接指标中是否存在该日期数据,如果拼接指标无此数据,那么需要删除该日期数据(日期的判断:需要在开始计算日期之后)
+	removeDateList := make([]string, 0)
+	for nowEdbDate := range nowEdbDataMap {
+		nowEdbDateTime, _ := time.ParseInLocation(utils.FormatDate, nowEdbDate, time.Local)
+		//校验日期 需要 大于 拼接前日期
+		if startCalculationDate.Before(nowEdbDateTime) {
+			if _, ok := tbzEdbDataMap[nowEdbDate]; !ok {
+				// 同比指标中,不存在该日期数据,那么需要移除 现有数据 中该日期的数据
+				removeDateList = append(removeDateList, nowEdbDate)
+			}
+		}
+	}
+
+	//待修改的指标数据map(index:日期,value:值)
+	updateEdbDataMap := make(map[string]float64)
+	for _, v := range tbzEdbDataTimeList {
+		tbzDataTime, _ := time.ParseInLocation(utils.FormatDate, v, time.Local)
+
+		//获取拼接指标上一年同一天的数据
+		var pjDataTime time.Time
+		if tbzDataTime.Month() == 2 {
+			pjDataTime = tbzDataTime.AddDate(0, -11, 0)
+			pjDataTime = time.Date(pjDataTime.Year(), pjDataTime.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 0, -1)
+		} else {
+			pjDataTime = tbzDataTime.AddDate(-1, 0, 0)
+		}
+
+		//校验现有数据中,是否存在该日期的数据,如果存在的话,那么就要去校验 最新计算数据 与 现有数据 是否一致
+		if nowEdbDataValue, isHas := nowEdbDataMap[v]; isHas {
+			//获取去年今日的数据,获取到后,然后是去修改该日期的数据
+			if lastYearEdbDataValue, ok := nowEdbDataMap[pjDataTime.Format(utils.FormatDate)]; ok {
+
+				if v == "2021-08-31" {
+					fmt.Println("进来了")
+				}
+				tbzDataValue := tbzEdbDataMap[v] //同比值
+				currValue := lastYearEdbDataValue * (1 + tbzDataValue/100)
+				currValue, _ = decimal.NewFromFloat(currValue).Truncate(4).Float64() //保留4位小数
+				//如果计算出来的值与库里面的值不匹配,那么就去修改该值
+				if nowEdbDataValue != currValue {
+					//将计算后的数据存入待拼接指标map里面,以便后续计算
+					updateEdbDataMap[v] = currValue
+				}
+			}
+		} else {
+			//因为 现有数据中 不存在该日期数据,那么需要做新增数据处理
+
+			//如果去年今日存在该数据,那么就去计算当前的数据
+			if pjDataValue, ok := nowEdbDataMap[pjDataTime.Format(utils.FormatDate)]; ok {
+				tbzDataValue := tbzEdbDataMap[v] //同比值
+				currValue := pjDataValue * (1 + tbzDataValue/100)
+
+				currValue, _ = decimal.NewFromFloat(currValue).Truncate(4).Float64()
+				//将计算后的数据存入已入库指标map里面,以便后续计算
+				nowEdbDataMap[v] = currValue
+
+				//将计算后的数据存入待拼接指标map里面,以便后续入库
+				pjDataMap[v] = currValue
+				pjEdbDataTimeList = append(pjEdbDataTimeList, v)
+			}
+		}
+	}
+
+	//新增的数据入库
+	{
+		addDataList := make([]*EdbDataCalculateLjztbpj, 0)
+		for dataTime, dataValue := range pjDataMap {
+			//时间戳
+			currentDate, _ := time.Parse(utils.FormatDate, dataTime)
+			timestamp := currentDate.UnixNano() / 1e6
+
+			edbDataLjztbpj := &EdbDataCalculateLjztbpj{
+				EdbInfoId:     edbInfo.EdbInfoId,
+				EdbCode:       edbInfo.EdbCode,
+				DataTime:      dataTime,
+				Value:         dataValue,
+				Status:        1,
+				CreateTime:    time.Now(),
+				ModifyTime:    time.Now(),
+				DataTimestamp: timestamp,
+			}
+			addDataList = append(addDataList, edbDataLjztbpj)
+		}
+
+		tmpAddDataList := make([]*EdbDataCalculateLjztbpj, 0)
+		for _, v := range addDataList {
+			tmpAddDataList = append(tmpAddDataList, v)
+
+			if len(tmpAddDataList) >= 200 {
+				_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
+				if tmpErr != nil {
+					err = tmpErr
+					return
+				}
+				//重新初始化需要加入的数据切片
+				tmpAddDataList = make([]*EdbDataCalculateLjztbpj, 0)
+			}
+		}
+		//最后如果还有需要新增的数据,那么就统一入库
+		if len(tmpAddDataList) > 0 {
+			_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
+			if tmpErr != nil {
+				err = tmpErr
+				return
+			}
+		}
+	}
+
+	//删除已经不存在的累计同比拼接指标数据(由于同比值当日的数据删除了)
+	{
+		if len(removeDateList) > 0 {
+			removeDateStr := strings.Join(removeDateList, `","`)
+			removeDateStr = `"` + removeDateStr + `"`
+			//如果拼接指标变更了,那么需要删除所有的指标数据
+			tableName := GetEdbDataTableName(edbInfo.Source)
+			sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
+
+			_, err = o.Raw(sql, edbInfo.EdbInfoId).Exec()
+			if err != nil {
+				err = errors.New("删除不存在的累计值同比拼接指标数据失败,Err:" + err.Error())
+				return
+			}
+		}
+	}
+
+	//修改现有的数据中对应的值
+	{
+		tableName := GetEdbDataTableName(edbInfo.Source)
+		for edbDate, edbDataValue := range updateEdbDataMap {
+			sql := fmt.Sprintf(` UPDATE  %s set value = ?,modify_time=now() WHERE edb_info_id = ? and data_time = ? `, tableName)
+
+			_, err = o.Raw(sql, edbDataValue, edbInfo.EdbInfoId, edbDate).Exec()
+			if err != nil {
+				err = errors.New("更新现有的累计值同比拼接指标数据失败,Err:" + err.Error())
+				return
+			}
+		}
+	}
+	return
+}

+ 1 - 1
models/data_manage/edb_info_calculate_ljzzy.go

@@ -194,7 +194,7 @@ type EdbInfoCalculateLjzzyDetail struct {
 func GetEdbInfoCalculateLjzzyDetail(edbInfoId int) (item *EdbInfoCalculateLjzzyDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_ljzzy AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? `
 	err = o.Raw(sql, edbInfoId).QueryRow(&item)

+ 32 - 0
models/data_manage/edb_info_calculate_mapping.go

@@ -80,3 +80,35 @@ func FixEdbInfoCalculateMapping() {
 		}
 	}
 }
+
+type EdbInfoCalculateMappingView struct {
+	EdbInfoCalculateMappingId int       `orm:"column(edb_info_calculate_mapping_id);pk"`
+	EdbInfoId                 int       `description:"计算指标id"`
+	Source                    int       `description:"计算指标来源"`
+	SourceName                string    `description:"计算指标来源名称"`
+	EdbCode                   string    `description:"计算指标编码"`
+	FromEdbInfoId             int       `description:"基础指标id"`
+	FromEdbCode               string    `description:"基础指标编码"`
+	FromEdbName               string    `description:"基础指标名称"`
+	FromSource                int       `description:"基础指标来源"`
+	FromSourceName            string    `description:"基础指标来源名称"`
+	FromTag                   string    `description:"来源指标标签"`
+	Sort                      int       `description:"计算指标名称排序"`
+	CreateTime                time.Time `description:"创建时间"`
+	ModifyTime                time.Time `description:"修改时间"`
+	StartDate                 string    `description:"开始日期"`
+	EndDate                   string    `description:"结束日期"`
+	CalculateFormula          string    `description:"N值"`
+	MoveType                  int       `description:"移动方式:1:领先(默认),2:滞后"`
+	MoveFrequency             string    `description:"移动频度"`
+}
+
+func GetEdbInfoCalculateMappingDetail(edbInfoId int) (item *EdbInfoCalculateMappingView, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := ` SELECT a.*,b.start_date,b.end_date,b.calculate_formula,b.move_type,b.move_frequency FROM edb_info_calculate_mapping AS a
+			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
+			WHERE a.edb_info_id=? `
+	err = o.Raw(sql, edbInfoId).QueryRow(&item)
+	return
+}

+ 4 - 23
models/data_manage/edb_info_calculate_nszydpjjs.go

@@ -49,28 +49,22 @@ func RefreshCalculateNszydpjjs(edbInfoId, source, formulaInt int, fromEdbInfo *E
 	condition += " AND edb_info_id=? "
 	pars = append(pars, edbInfoId)
 
-	dataList, err := GetEdbDataListAll(condition, pars, source, 0)
+	dataList, err := GetEdbDataListAllV1(condition, pars, source, 0)
 	if err != nil {
 		return err
 	}
 
-	existDataMap := make(map[string]*EdbInfoSearchData)
+	existDataMap := make(map[string]*EdbInfoSearchDataV1)
 	for _, v := range dataList {
-		utils.FileLog.Info("exist:",v.DataTime,v.Value)
 		existDataMap[v.DataTime] = v
 	}
 
-	fmt.Println("existDataMap:",existDataMap)
-
 	//计算来源数据
-	//startDate := time.Now().AddDate(-2, 0, 0).Format(utils.FormatDate)
 
 	var fromCondition string
 	var fromPars []interface{}
 	fromCondition += " AND edb_info_id=? "
 	fromPars = append(fromPars, fromEdbInfo.EdbInfoId)
-	//fromCondition += " AND data_time>=? "
-	//fromPars = append(fromPars, startDate)
 
 	fromDataList, err := GetEdbDataListAll(fromCondition, fromPars, fromEdbInfo.Source, 0)
 	if err != nil {
@@ -133,23 +127,10 @@ func RefreshCalculateNszydpjjs(edbInfoId, source, formulaInt int, fromEdbInfo *E
 		valStr := utils.SubFloatToString(val, 4)
 
 		if existItem, existOk := existDataMap[av]; !existOk {
-			//count, err := GetEdbDataCalculateNszydpjjsByCodeAndDate(edbCode, av)
-			//if err != nil && err.Error() != utils.ErrNoRow() {
-			//	return err
-			//}
-			//if count <= 0 {
-			//	addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, valStr)
-			//	isAdd = true
-			//} else {
-			//	err = ModifyEdbDataCalculateNszydpjjs(int64(edbInfoId), av, valStr)
-			//	if err != nil {
-			//		return err
-			//	}
-			//}
 			addSql += GetAddSql(edbInfoIdStr, edbCode, av, timestampStr, valStr)
 			isAdd = true
 		} else {
-			if existItem.Value != val {
+			if existItem != nil && existItem.Value != valStr {
 				err = ModifyEdbDataCalculateNszydpjjs(int64(edbInfoId), av, valStr)
 				if err != nil {
 					return err
@@ -188,7 +169,7 @@ type EdbInfoCalculateNszydpjjsDetail struct {
 func GetEdbInfoCalculateNszydpjjsDetail(edbInfoId int) (item *EdbInfoCalculateNszydpjjsDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_nszydpjjs AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? `
 	err = o.Raw(sql, edbInfoId).QueryRow(&item)

+ 7 - 7
models/data_manage/edb_info_calculate_tbz.go

@@ -93,7 +93,7 @@ func RefreshCalculateTbz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate
 			//上一年的日期
 			preDate := currentDate.AddDate(-1, 0, 0)
 			preDateStr := preDate.Format(utils.FormatDate)
-			if findItem, ok := dataMap[preDateStr]; ok { //上一年同期找到
+			if findItem, ok := dataMap[preDateStr]; ok && findItem.Value != 0 { //上一年同期找到
 				//dataTime, _ := time.Parse(utils.FormatDate, date)
 				timestamp := currentDate.UnixNano() / 1e6
 				timestampStr := fmt.Sprintf("%d", timestamp)
@@ -127,7 +127,7 @@ func RefreshCalculateTbz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate
 							nextDateDay = nextDateDay.AddDate(0, 0, i)
 							nextDateDayStr = nextDateDay.Format(utils.FormatDate)
 						}
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
+						if findItem, ok := dataMap[nextDateDayStr]; ok && findItem.Value != 0 { //上一年同期->下一个月找到
 							timestamp := currentDate.UnixNano() / 1e6
 							timestampStr := fmt.Sprintf("%d", timestamp)
 							val := TbzDiv(currentItem.Value, findItem.Value)
@@ -151,7 +151,7 @@ func RefreshCalculateTbz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate
 								preDateDay = preDate.AddDate(0, 0, -i)
 								preDateDayStr = nextDateDay.Format(utils.FormatDate)
 							}
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
+							if findItem, ok := dataMap[preDateDayStr]; ok && findItem.Value != 0 { //上一年同期->上一个月找到
 								timestamp := currentDate.UnixNano() / 1e6
 								timestampStr := fmt.Sprintf("%d", timestamp)
 								val := TbzDiv(currentItem.Value, findItem.Value)
@@ -174,7 +174,7 @@ func RefreshCalculateTbz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate
 						}
 					}
 				} else if fromEdbInfo.Frequency == "季度" || fromEdbInfo.Frequency == "年度" {
-					if findItem, ok := dataMap[preDateStr]; ok { //上一年同期->下一个月找到
+					if findItem, ok := dataMap[preDateStr]; ok && findItem.Value != 0 { //上一年同期->下一个月找到
 						timestamp := currentDate.UnixNano() / 1e6
 						timestampStr := fmt.Sprintf("%d", timestamp)
 						val := TbzDiv(currentItem.Value, findItem.Value)
@@ -200,7 +200,7 @@ func RefreshCalculateTbz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate
 
 					for i := 0; i < 35; i++ {
 						nextDateDayStr := nextDateDay.Format(utils.FormatDate)
-						if findItem, ok := dataMap[nextDateDayStr]; ok { //上一年同期->下一个月找到
+						if findItem, ok := dataMap[nextDateDayStr]; ok && findItem.Value != 0 { //上一年同期->下一个月找到
 							timestamp := currentDate.UnixNano() / 1e6
 							timestampStr := fmt.Sprintf("%d", timestamp)
 							val := TbzDiv(currentItem.Value, findItem.Value)
@@ -221,7 +221,7 @@ func RefreshCalculateTbz(edbInfoId int, fromEdbInfo *EdbInfo, edbCode, startDate
 							break
 						} else {
 							preDateDayStr := preDateDay.Format(utils.FormatDate)
-							if findItem, ok := dataMap[preDateDayStr]; ok { //上一年同期->上一个月找到
+							if findItem, ok := dataMap[preDateDayStr]; ok && findItem.Value != 0 { //上一年同期->上一个月找到
 								timestamp := currentDate.UnixNano() / 1e6
 								timestampStr := fmt.Sprintf("%d", timestamp)
 								val := TbzDiv(currentItem.Value, findItem.Value)
@@ -279,7 +279,7 @@ type EdbInfoCalculateTbzDetail struct {
 func GetEdbInfoCalculateTbzDetail(edbInfoId int) (item *EdbInfoCalculateTbzDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_tbz AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? `
 	err = o.Raw(sql, edbInfoId).QueryRow(&item)

+ 1 - 1
models/data_manage/edb_info_calculate_tcz.go

@@ -280,7 +280,7 @@ type EdbInfoCalculateTczDetail struct {
 func GetEdbInfoCalculateTczDetail(edbInfoId int) (item *EdbInfoCalculateTczDetail, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
-	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_tcz AS a
+	sql := ` SELECT a.*,b.start_date,b.end_date FROM edb_info_calculate_mapping AS a
 			INNER JOIN edb_info AS b ON a.from_edb_info_id=b.edb_info_id
 			WHERE a.edb_info_id=? `
 	err = o.Raw(sql, edbInfoId).QueryRow(&item)

+ 3 - 0
models/data_manage/edb_info_calculate_time_shift.go

@@ -0,0 +1,3 @@
+package data_manage
+
+//时间移位

+ 223 - 0
models/data_manage/edb_info_calculate_zjpj.go

@@ -0,0 +1,223 @@
+package data_manage
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_task/utils"
+	"rdluck_tools/orm"
+	"strings"
+	"time"
+)
+
+type EdbInfoCalculateZjpjDetail struct {
+	EdbInfoCalculateBpId int       `orm:"column(edb_info_calculate_bp_id);pk"`
+	EdbInfoId            int       `description:"指标id"`
+	EdbCode              string    `description:"指标编码"`
+	FromEdbInfoId        int       `description:"计算指标id"`
+	FromEdbCode          string    `description:"计算指标编码"`
+	FromEdbName          string    `description:"计算指标名称"`
+	FromSource           int       `description:"计算指标来源"`
+	FromSourceName       string    `description:"计算指标来源名称"`
+	FromTag              string    `description:"来源指标标签"`
+	Sort                 int       `description:"计算指标名称排序"`
+	CreateTime           time.Time `description:"创建时间"`
+	ModifyTime           time.Time `description:"修改时间"`
+	StartDate            string    `description:"开始日期"`
+	EndDate              string    `description:"结束日期"`
+}
+
+// RefreshAllCalculateZjpj 刷新所有 直接拼接 数据
+func RefreshAllCalculateZjpj(edbInfo *EdbInfoList) (err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	o.Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+
+	//查询当前指标现有的数据
+	var condition string
+	var pars []interface{}
+	condition += " AND edb_info_id=? "
+	pars = append(pars, edbInfo.EdbInfoId)
+
+	dataList, err := GetAllEdbDataCalculateZjpjByEdbInfoId(edbInfo.EdbInfoId)
+	if err != nil {
+		return err
+	}
+	var dateArr []string
+	dataMap := make(map[string]*EdbDataCalculateZjpj)
+	removeDataTimeMap := make(map[string]int) //需要移除的日期数据
+	for _, v := range dataList {
+		dateArr = append(dateArr, v.DataTime)
+		dataMap[v.DataTime] = v
+		removeDataTimeMap[v.DataTime] = 1
+	}
+
+	//查询关联指标信息
+	var existCondition string
+	var existPars []interface{}
+	existCondition += " AND edb_info_id=? "
+	existPars = append(existPars, edbInfo.EdbInfoId)
+	existList, err := GetEdbInfoCalculateListByCondition(existCondition, existPars)
+	if err != nil {
+		err = errors.New("判断指标是否改变失败,Err:" + err.Error())
+		return
+	}
+
+	var existItemA, existItemB *EdbInfoCalculateMapping
+	for _, existItem := range existList {
+		if existItem.FromTag == "A" {
+			existItemA = existItem
+		} else if existItem.FromTag == "B" {
+			existItemB = existItem
+		}
+	}
+
+	addDataList := make([]*EdbDataCalculateZjpj, 0)
+	//第一个指标
+	{
+		var condition string
+		var pars []interface{}
+
+		condition += " AND data_time < ? AND edb_info_id=? "
+		pars = append(pars, edbInfo.CalculateFormula, existItemA.FromEdbInfoId)
+
+		//第一个指标的数据列表
+		firstDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemA.FromSource, 0)
+		if tmpErr != nil {
+			return tmpErr
+		}
+
+		for _, v := range firstDataList {
+			//校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该元素
+			if _, ok := removeDataTimeMap[v.DataTime]; ok {
+				delete(removeDataTimeMap, v.DataTime)
+			}
+			//时间戳
+			if edbData, ok := dataMap[v.DataTime]; ok {
+				if edbData.Value != v.Value {
+					//更新指标数据
+					edbData.Value = v.Value
+					o.Update(edbData, "Value")
+				}
+			} else {
+				//时间戳
+				currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
+				timestamp := currentDate.UnixNano() / 1e6
+
+				edbDataZjpj := &EdbDataCalculateZjpj{
+					EdbInfoId:     edbInfo.EdbInfoId,
+					EdbCode:       edbInfo.EdbCode,
+					DataTime:      v.DataTime,
+					Value:         v.Value,
+					Status:        1,
+					CreateTime:    time.Now(),
+					ModifyTime:    time.Now(),
+					DataTimestamp: timestamp,
+				}
+				addDataList = append(addDataList, edbDataZjpj)
+			}
+		}
+	}
+
+	//第二个指标
+	{
+		condition = ``
+		pars = make([]interface{}, 0)
+
+		condition += " AND data_time >= ? AND edb_info_id = ? "
+		pars = append(pars, edbInfo.CalculateFormula, existItemB.FromEdbInfoId)
+
+		//第二个指标的数据列表
+		secondDataList, tmpErr := GetEdbDataListAll(condition, pars, existItemB.FromSource, 0)
+		if tmpErr != nil {
+			return tmpErr
+		}
+
+		for _, v := range secondDataList {
+			//校验待删除日期数据里面是否存在该元素,如果存在的话,那么移除该元素
+			if _, ok := removeDataTimeMap[v.DataTime]; ok {
+				delete(removeDataTimeMap, v.DataTime)
+			}
+
+			if edbData, ok := dataMap[v.DataTime]; ok {
+				if edbData.Value != v.Value {
+					//更新指标数据
+					edbData.Value = v.Value
+					edbData.ModifyTime = time.Now()
+					_, tmpErr := o.Update(edbData, "Value", "ModifyTime")
+					if tmpErr != nil {
+						fmt.Println("tmpErr:", tmpErr)
+					}
+				}
+			} else {
+				//时间戳
+				currentDate, _ := time.Parse(utils.FormatDate, v.DataTime)
+				timestamp := currentDate.UnixNano() / 1e6
+
+				edbDataZjpj := &EdbDataCalculateZjpj{
+					EdbInfoId:     edbInfo.EdbInfoId,
+					EdbCode:       edbInfo.EdbCode,
+					DataTime:      v.DataTime,
+					Value:         v.Value,
+					Status:        1,
+					CreateTime:    time.Now(),
+					ModifyTime:    time.Now(),
+					DataTimestamp: timestamp,
+				}
+				addDataList = append(addDataList, edbDataZjpj)
+			}
+		}
+	}
+
+	//删除已经不存在的累计同比拼接指标数据(由于同比值当日的数据删除了)
+	{
+		removeDateList := make([]string, 0)
+		for dateTime := range removeDataTimeMap {
+			removeDateList = append(removeDateList, dateTime)
+		}
+		if len(removeDateList) > 0 {
+			removeDateStr := strings.Join(removeDateList, `","`)
+			removeDateStr = `"` + removeDateStr + `"`
+			//如果拼接指标变更了,那么需要删除所有的指标数据
+			tableName := GetEdbDataTableName(edbInfo.Source)
+			sql := fmt.Sprintf(` DELETE FROM %s WHERE edb_info_id = ? and data_time in (%s) `, tableName, removeDateStr)
+
+			_, err = o.Raw(sql, edbInfo.EdbInfoId).Exec()
+			if err != nil {
+				err = errors.New("删除不存在的直接拼接指标数据失败,Err:" + err.Error())
+				return
+			}
+		}
+	}
+
+	//数据入库
+	tmpAddDataList := make([]*EdbDataCalculateZjpj, 0)
+	for _, v := range addDataList {
+		tmpAddDataList = append(tmpAddDataList, v)
+
+		if len(tmpAddDataList) >= 200 {
+			_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
+			if tmpErr != nil {
+				err = tmpErr
+				return
+			}
+			//重新初始化需要加入的数据切片
+			tmpAddDataList = make([]*EdbDataCalculateZjpj, 0)
+		}
+	}
+	//最后如果还有需要新增的数据,那么就统一入库
+	if len(tmpAddDataList) > 0 {
+		_, tmpErr := o.InsertMulti(len(tmpAddDataList), tmpAddDataList)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+	}
+	return
+}

+ 4 - 0
models/db.go

@@ -89,5 +89,9 @@ func init() {
 		new(yb.ActivityRegister), //研报活动报名表
 		new(yb.Speaker),          //研报主持人表
 		new(UserViewStatistics),
+		new(data_manage.EdbInfo), //hz_data库的edb_info表
+		new(data_manage.EdbInfoCalculateMapping),
+		new(data_manage.EdbDataCalculateZjpj),    //直接拼接
+		new(data_manage.EdbDataCalculateLjztbpj), //累计同比值拼接
 	)
 }

+ 42 - 0
services/data/chart_info.go

@@ -0,0 +1,42 @@
+package data
+
+import (
+	"fmt"
+	"hongze/hongze_task/models/data_manage"
+)
+
+//设置图表中,指标的最新日期
+func SetChartEdbEndDate() {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("SetChartEdbEndDate err:" + err.Error())
+		}
+	}()
+
+	allList, err := data_manage.GetAllChartInfo()
+	if err != nil {
+		return
+	}
+
+	allMap := make(map[int]*data_manage.ChartInfo)
+	for _, v := range allList {
+		allMap[v.ChartInfoId] = v
+	}
+
+	list, err := data_manage.GetChartInfoEdbEndDate()
+	if err != nil {
+		return
+	}
+
+	for _, sv := range list {
+		if findItem, ok := allMap[sv.ChartInfoId]; ok {
+			if findItem.EdbEndDate != sv.EdbEndDate {
+				err = data_manage.ModifyChartInfoEdbEndDate(sv.ChartInfoId, sv.EdbEndDate)
+				if err != nil {
+					return
+				}
+			}
+		}
+	}
+}

+ 2 - 2
services/data/data_ths.go

@@ -28,9 +28,9 @@ func SyncEdbDataByThs(edbInfoId int64, edbCode, startDate, endDate string) (err
 	thsUrl = fmt.Sprintf(thsUrl, edbCode, startDate, endDate)
 	utils.FileLog.Info("thsUrl:" + thsUrl)
 	body, err := http.Get(thsUrl)
-
 	if strings.Contains(string(body), "html") {
-		return nil
+		err = errors.New("SyncEdbDataByThs Err:" + string(body))
+		return err
 	}
 	utils.FileLog.Info("ths result:" + string(body))
 	if err != nil {

+ 320 - 22
services/data/edb_info.go

@@ -25,9 +25,11 @@ func RefreshDataFromThs(wg *sync.WaitGroup) (err error) {
 	var pars []interface{}
 	condition += " AND source=? "
 	pars = append(pars, utils.DATA_SOURCE_THS)
+
 	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
 	if err != nil {
-		return errors.New("GetEdbInfoByCondition:" + err.Error())
+		err = errors.New("GetEdbInfoByCondition:" + err.Error())
+		return
 	}
 
 	var endDate string
@@ -49,27 +51,21 @@ func RefreshDataFromThs(wg *sync.WaitGroup) (err error) {
 		}
 		err = SyncEdbDataByThs(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
 		if err != nil {
-			return errors.New("SyncEdbDataByThs:" + err.Error())
+			err = errors.New("SyncEdbDataByThs Err:" + err.Error())
+			return err
 		}
 		item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
 		if err != nil {
+			err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error())
 			return err
 		}
 		if item != nil {
 			err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
 			if err != nil {
+				err = errors.New("ModifyEdbInfoMaxAndMinInfo Err:" + err.Error())
 				return err
 			}
 		}
-		//minDate, maxDate, err := data.GetEdbDataThsMaxOrMinDate(v.EdbInfoId)
-		//if err != nil {
-		//	return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error())
-		//}
-		//fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
-		//err = data.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
-		//if err != nil {
-		//	return errors.New("ModifyEdbDataInfoDate:" + err.Error())
-		//}
 	}
 	return err
 }
@@ -245,8 +241,7 @@ func RefreshDataFromCalculateAll() (err error) {
 	condition += " AND edb_type=? "
 	pars = append(pars, 2)
 
-	//condition += " AND source=? "
-	//pars = append(pars, utils.DATA_SOURCE_CALCULATE_BP)
+	condition += " AND is_update=1 "
 
 	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
 	if err != nil {
@@ -256,7 +251,7 @@ func RefreshDataFromCalculateAll() (err error) {
 		edbInfoId := v.EdbInfoId
 		edbCode := v.EdbCode
 		source := v.Source
-		fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName)
+		fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
 		if source == utils.DATA_SOURCE_CALCULATE {
 			startDate := ""
 			if v.Frequency == "日度" {
@@ -302,7 +297,7 @@ func RefreshDataFromCalculateAll() (err error) {
 			}
 			year := time.Now().Year() - 1
 			startDate := strconv.Itoa(year) + "-01" + "-01"
-			endDate := ""//time.Now().Format(utils.FormatDate)
+			endDate := "" //time.Now().Format(utils.FormatDate)
 			err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, edbCode, startDate, endDate)
 			if err != nil {
 				return errors.New("RefreshCalculateLjzzy Err:" + err.Error())
@@ -317,7 +312,7 @@ func RefreshDataFromCalculateAll() (err error) {
 				return errors.New("GetEdbInfoById Err:" + err.Error())
 			}
 			startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
-			endDate := ""//time.Now().Format(utils.FormatDate)
+			endDate := "" //time.Now().Format(utils.FormatDate)
 			err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
 			if err != nil {
 				return errors.New("RefreshCalculateTbz Err:" + err.Error())
@@ -332,7 +327,7 @@ func RefreshDataFromCalculateAll() (err error) {
 				return errors.New("GetEdbInfoById Err:" + err.Error())
 			}
 			startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
-			endDate := ""//time.Now().Format(utils.FormatDate)
+			endDate := "" //time.Now().Format(utils.FormatDate)
 			err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
 			if err != nil {
 				return errors.New("RefreshCalculateTcz Err:" + err.Error())
@@ -360,9 +355,10 @@ func RefreshDataFromCalculateAll() (err error) {
 			if err != nil {
 				return errors.New("GetEdbInfoById Err:" + err.Error())
 			}
-			startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
-			endDate := ""//time.Now().Format(utils.FormatDate)
-			err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateHbz.EdbCode, startDate, endDate)
+			//startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
+			//endDate := "" //time.Now().Format(utils.FormatDate)
+			formulaInt, _ := strconv.Atoi(v.CalculateFormula)
+			err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateHbz.EdbCode, formulaInt)
 			if err != nil {
 				return errors.New("RefreshCalculateTbz Err:" + err.Error())
 			}
@@ -376,7 +372,7 @@ func RefreshDataFromCalculateAll() (err error) {
 				return errors.New("GetEdbInfoById Err:" + err.Error())
 			}
 			startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
-			endDate := ""//time.Now().Format(utils.FormatDate)
+			endDate := "" //time.Now().Format(utils.FormatDate)
 			err = data_manage.RefreshCalculateHcz(edbInfoId, source, fromEdbInfo, calculateHcz.EdbCode, startDate, endDate)
 			if err != nil {
 				return errors.New("RefreshCalculateTbz Err:" + err.Error())
@@ -392,12 +388,39 @@ func RefreshDataFromCalculateAll() (err error) {
 					return errors.New("GetEdbInfoById Err:" + err.Error())
 				}
 				startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
-				endDate := ""//time.Now().Format(utils.FormatDate)
+				endDate := "" //time.Now().Format(utils.FormatDate)
 				err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateBp.EdbCode, startDate, endDate)
 				if err != nil {
 					return errors.New("RefreshCalculateTbz Err:" + err.Error())
 				}
 			}
+		} else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
+			calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
+			if err != nil {
+				return fmt.Errorf("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
+			}
+			fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
+			if err != nil {
+				return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
+			}
+			startDate := v.StartDate.Format(utils.FormatDate)
+			endDate := time.Now().Format(utils.FormatDate)
+			formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
+			err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, startDate, endDate, calculate.MoveFrequency)
+			if err != nil {
+				return fmt.Errorf("RefreshAllCalculateTimeShift Err:" + err.Error())
+			}
+
+		} else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
+			err = data_manage.RefreshAllCalculateZjpj(v)
+			if err != nil {
+				return fmt.Errorf("RefreshAllCalculateZjpj Err:" + err.Error())
+			}
+		} else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接
+			err = data_manage.RefreshAllCalculateLjztbpj(v)
+			if err != nil {
+				return fmt.Errorf("RefreshAllCalculateLjztbpj Err:" + err.Error())
+			}
 		} else {
 			msg := "刷新失败,无效的指标渠道:source:" + strconv.Itoa(source) + " EdbCode:" + v.EdbCode
 			err = errors.New(msg)
@@ -406,6 +429,8 @@ func RefreshDataFromCalculateAll() (err error) {
 
 		maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
 		if err != nil {
+			fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
+			err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
 			return err
 		}
 		if maxAndMinItem != nil {
@@ -431,6 +456,7 @@ func RefreshDataFromManual(wg *sync.WaitGroup) (err error) {
 	var pars []interface{}
 	condition += " AND source=? "
 	pars = append(pars, utils.DATA_SOURCE_MANUAL)
+
 	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
 	if err != nil {
 		return errors.New("GetEdbInfoByCondition:" + err.Error())
@@ -484,6 +510,7 @@ func RefreshDataFromLz(wg *sync.WaitGroup) (err error) {
 	var pars []interface{}
 	condition += " AND source=? "
 	pars = append(pars, utils.DATA_SOURCE_LZ)
+
 	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
 	if err != nil {
 		return errors.New("GetEdbInfoByCondition:" + err.Error())
@@ -538,6 +565,7 @@ func RefreshDataFromYs(wg *sync.WaitGroup) (err error) {
 	var pars []interface{}
 	condition += " AND source=? "
 	pars = append(pars, utils.DATA_SOURCE_YS)
+
 	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
 	if err != nil {
 		return errors.New("GetEdbInfoByCondition:" + err.Error())
@@ -633,6 +661,276 @@ func RefreshDataFromGl(wg *sync.WaitGroup) (err error) {
 	return err
 }
 
+// RefreshDataFromSh 刷新上期所数据
+func RefreshDataFromSh(wg *sync.WaitGroup) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromSh Err:" + err.Error())
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromSh ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+		wg.Done()
+	}()
+	var condition string
+	var pars []interface{}
+	condition += " AND source=? "
+	pars = append(pars, utils.DATA_SOURCE_SH)
+	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
+	if err != nil {
+		return errors.New("GetEdbInfoByCondition:" + err.Error())
+	}
+
+	var endDate string
+	endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
+	for _, v := range items {
+		startDate := ""
+		if v.Frequency == "日度" {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		} else if v.Frequency == "周度" {
+			startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
+		} else if v.Frequency == "月度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "季度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "年度" {
+			startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
+		} else {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		}
+		fmt.Println(startDate, endDate)
+		err = data_manage.RefreshEdbDataBySh(v.EdbInfoId, v.EdbCode, startDate, endDate)
+		if err != nil {
+			return errors.New("RefreshEdbDataBySh:" + err.Error())
+		}
+		item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
+		if err != nil {
+			return err
+		}
+		if item != nil {
+			err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return err
+}
+
+// RefreshDataFromDl 刷新大商所数据
+func RefreshDataFromDl(wg *sync.WaitGroup) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromDl Err:" + err.Error())
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromDl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+		wg.Done()
+	}()
+	var condition string
+	var pars []interface{}
+	condition += " AND source=? "
+	pars = append(pars, utils.DATA_SOURCE_DL)
+	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
+	if err != nil {
+		return errors.New("GetEdbInfoByCondition:" + err.Error())
+	}
+
+	var endDate string
+	endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
+	for _, v := range items {
+		startDate := ""
+		if v.Frequency == "日度" {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		} else if v.Frequency == "周度" {
+			startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
+		} else if v.Frequency == "月度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "季度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "年度" {
+			startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
+		} else {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		}
+		fmt.Println(startDate, endDate)
+		err = data_manage.RefreshEdbDataByDl(v.EdbInfoId, v.EdbCode, startDate, endDate)
+		if err != nil {
+			return errors.New("RefreshEdbDataByDl:" + err.Error())
+		}
+		item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
+		if err != nil {
+			return err
+		}
+		if item != nil {
+			err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return err
+}
+
+// RefreshDataFromShfe 刷新上期能源数据
+func RefreshDataFromShfe(wg *sync.WaitGroup) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromShfe Err:" + err.Error())
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromShfe ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+		wg.Done()
+	}()
+	var condition string
+	var pars []interface{}
+	condition += " AND source=? "
+	pars = append(pars, utils.DATA_SOURCE_SHFE)
+	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
+	if err != nil {
+		return errors.New("GetEdbInfoByCondition:" + err.Error())
+	}
+
+	var endDate string
+	endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
+	for _, v := range items {
+		startDate := ""
+		if v.Frequency == "日度" {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		} else if v.Frequency == "周度" {
+			startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
+		} else if v.Frequency == "月度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "季度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "年度" {
+			startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
+		} else {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		}
+		fmt.Println(startDate, endDate)
+		err = data_manage.RefreshEdbDataByShfe(v.EdbInfoId, v.EdbCode, startDate, endDate)
+		if err != nil {
+			return errors.New("RefreshEdbDataByShfe:" + err.Error())
+		}
+		item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
+		if err != nil {
+			return err
+		}
+		if item != nil {
+			err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return err
+}
+
+// RefreshDataFromCffex 刷新中金所数据
+func RefreshDataFromCffex(wg *sync.WaitGroup) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromCffex Err:" + err.Error())
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCffex ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+		wg.Done()
+	}()
+	var condition string
+	var pars []interface{}
+	condition += " AND source=? "
+	pars = append(pars, utils.DATA_SOURCE_CFFEX)
+	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
+	if err != nil {
+		return errors.New("GetEdbInfoByCondition:" + err.Error())
+	}
+
+	var endDate string
+	endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
+	for _, v := range items {
+		startDate := ""
+		if v.Frequency == "日度" {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		} else if v.Frequency == "周度" {
+			startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
+		} else if v.Frequency == "月度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "季度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "年度" {
+			startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
+		} else {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		}
+		fmt.Println(startDate, endDate)
+		err = data_manage.RefreshEdbDataByCffex(v.EdbInfoId, v.EdbCode, startDate, endDate)
+		if err != nil {
+			return errors.New("RefreshEdbDataByCffex:" + err.Error())
+		}
+		item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
+		if err != nil {
+			return err
+		}
+		if item != nil {
+			err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return err
+}
+
+// RefreshDataFromZz 刷新郑商所数据
+func RefreshDataFromZz(wg *sync.WaitGroup) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromZz Err:" + err.Error())
+			go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromZz ErrMsg:"+err.Error(), utils.EmailSendToUsers)
+		}
+		wg.Done()
+	}()
+	var condition string
+	var pars []interface{}
+	condition += " AND source=? "
+	pars = append(pars, utils.DATA_SOURCE_ZZ)
+	items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
+	if err != nil {
+		return errors.New("GetEdbInfoByCondition:" + err.Error())
+	}
+
+	var endDate string
+	endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
+	for _, v := range items {
+		startDate := ""
+		if v.Frequency == "日度" {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		} else if v.Frequency == "周度" {
+			startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
+		} else if v.Frequency == "月度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "季度" {
+			startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
+		} else if v.Frequency == "年度" {
+			startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
+		} else {
+			startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
+		}
+		fmt.Println(startDate, endDate)
+		err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate)
+		if err != nil {
+			return errors.New("RefreshEdbDataByZz:" + err.Error())
+		}
+		item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
+		if err != nil {
+			return err
+		}
+		if item != nil {
+			err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
+			if err != nil {
+				return err
+			}
+		}
+	}
+	return err
+}
+
 func ResetEdbInfoIsUpdate(cont context.Context) (err error) {
 	go data_manage.ResetEdbInfoIsUpdate()
 	return nil

+ 39 - 28
services/task.go

@@ -22,23 +22,23 @@ func Task() {
 		releaseTask()
 	}
 	//每日定时合同处理
-	handleCompanyContract := task.NewTask("handleCompanyContract", "0 1 0 * * *", company_contract.HandleCompanyContract)
+	handleCompanyContract := task.NewTask("handleCompanyContract", "0 1 2 * * *", company_contract.HandleCompanyContract)
 	task.AddTask("每日定时合同处理", handleCompanyContract)
 
 	//正式->试用
-	companyTryOut := task.NewTask("companyTryOut", "0 5 0 * * *", CompanyTryOut)
+	companyTryOut := task.NewTask("companyTryOut", "0 5 2 * * *", CompanyTryOut)
 	task.AddTask("正式->试用", companyTryOut)
 
 	//试用->冻结
-	companyFreeze := task.NewTask("companyFreeze", "0 10 0 * * *", CompanyFreeze)
+	companyFreeze := task.NewTask("companyFreeze", "0 10 2 * * *", CompanyFreeze)
 	task.AddTask("试用->冻结", companyFreeze)
 
 	//冻结->流失
-	companyLoss := task.NewTask("companyLoss", "0 20 0 * * *", CompanyLoss)
+	companyLoss := task.NewTask("companyLoss", "0 20 2 * * *", CompanyLoss)
 	task.AddTask("冻结->流失", companyLoss)
 
 	//用户产品权限试用-->关闭
-	companyReportPermissionClose := task.NewTask("companyReportPermissionClose", "0 30 0 * * *", CompanyReportPermissionClose)
+	companyReportPermissionClose := task.NewTask("companyReportPermissionClose", "0 30 2 * * *", CompanyReportPermissionClose)
 	task.AddTask("用户产品权限试用-->关闭", companyReportPermissionClose)
 
 	//删除日志记录
@@ -46,7 +46,7 @@ func Task() {
 	//task.AddTask("deleteReportSaveLog", deleteReportSaveLog)
 
 	// 存量客户数据统计
-	stackCompanyStatistic := task.NewTask("stackCompanyStatistic", "0 35 0 * * *", StackCompanyStatistic)
+	stackCompanyStatistic := task.NewTask("stackCompanyStatistic", "0 35 2 * * *", StackCompanyStatistic)
 	task.AddTask("存量客户数据统计", stackCompanyStatistic)
 
 	// 定时往同花顺推送报告
@@ -72,13 +72,13 @@ func Task() {
 	//GetLzProductList()GetLzProductDetail
 
 	// 定时新增手工指标数据提醒
-	addEdbTask := task.NewTask("sendWaitReport", "1 0 0 * * * ", AddEdbTask)
+	addEdbTask := task.NewTask("sendWaitReport", "1 0 2 * * * ", AddEdbTask)
 	task.AddTask("定时新增手工指标数据提醒", addEdbTask)
 	//每次服务启动都需要执行一次的
 	_ = AddEdbTask(nil)
 	
 	//每日用户阅读数据统计
-	statisticsUserView := task.NewTask("statisticsUserView", "0 5 0 * * *", StatisticsUserView)
+	statisticsUserView := task.NewTask("statisticsUserView", "0 5 2 * * *", StatisticsUserView)
 	task.AddTask("每日用户阅读数据统计", statisticsUserView)
 	
 	task.StartTask()
@@ -88,21 +88,6 @@ func Task() {
 
 //生产环境需要走的任务
 func releaseTask() {
-
-	//隆众指标获取
-	//getLzProductList := task.NewTask("getLzProductList", "0 0 11-19/1 * * * ", GetLzProductList)
-	//task.AddTask("getLzProductList", getLzProductList)
-	//隆众指标数据获取
-	//getLzProductDetail := task.NewTask("getLzProductDetail", "0 5 11-19/1 * * * ", GetLzProductDetail)
-	//task.AddTask("getLzProductDetail", getLzProductDetail)
-
-	//隆众价格指标获取
-	//getLzProductPriceProduct := task.NewTask("getLzProductPriceProduct", "0 5 11-19/1 * * * ", GetLzProductPriceProduct)
-	//task.AddTask("getLzProductPriceProduct", getLzProductPriceProduct)
-	//隆众价格指标数据获取
-	//getLzProductPriceData := task.NewTask("getLzProductPriceData", "0 10 11-19/1 * * * ", GetLzProductPriceData)
-	//task.AddTask("getLzProductPriceData", getLzProductPriceData)
-
 	//隆众调研指标获取
 	getLzSurveyProduct := task.NewTask("getLzSurveyProduct", "0 5 08-19/1 * * * ", GetLzSurveyProduct)
 	task.AddTask("getLzSurveyProduct", getLzSurveyProduct)
@@ -129,6 +114,10 @@ func releaseTask() {
 	refreshData := task.NewTask("refreshData", "0 1 0,19 * * *", RefreshData)
 	task.AddTask("refreshData", refreshData)
 
+	//刷新交易所指标数据
+	refreshTradeData := task.NewTask("refreshData", "0 1 4 * * *", RefreshTradeData)
+	task.AddTask("refreshTradeData", refreshTradeData)
+
 	//刷新指标基础数据
 	refreshBaseData := task.NewTask("refreshBaseData", "0 */30 * * * * ", RefreshBaseData)
 	task.AddTask("refreshBaseData", refreshBaseData)
@@ -144,14 +133,10 @@ func releaseTask() {
 	syncThsWxGroupEveryDay := task.NewTask("syncThsWxGroupEveryDay", "0 1 4 * * * ", SyncWxGroupEveryDay)
 	task.AddTask("定时往同花顺同步微信群的截止日期", syncThsWxGroupEveryDay)
 
-	//刷新计算指标数据
-	//refreshCalculateData := task.NewTask("refreshCalculateData", "0 15 0,19 * * *", RefreshCalculateData)
-	//task.AddTask("refreshCalculateData", refreshCalculateData)
-
 	checkDataInterface := task.NewTask("checkDataInterface", "0 */2 * * * * ", data.CheckDataInterface)
 	task.AddTask("checkDataInterface", checkDataInterface)
 
-	checkPbDataInterface := task.NewTask("checkPbDataInterface", "0 */5 * * * * ", data.CheckPbDataInterface)
+	checkPbDataInterface := task.NewTask("checkPbDataInterface", "0 */2 * * * * ", data.CheckPbDataInterface)
 	task.AddTask("checkPbDataInterface", checkPbDataInterface)
 }
 
@@ -211,6 +196,30 @@ func RefreshData(cont context.Context) (err error) {
 	return
 }
 
+// RefreshTradeData 刷新交易所数据
+func RefreshTradeData(cont context.Context) (err error) {
+	wg := sync.WaitGroup{}
+	wg.Add(5)
+
+	//郑商所
+	go data.RefreshDataFromZz(&wg)
+	//上期所
+	go data.RefreshDataFromSh(&wg)
+	//上期能源
+	go data.RefreshDataFromShfe(&wg)
+	//中金所
+	go data.RefreshDataFromCffex(&wg)
+	//大商所
+	go data.RefreshDataFromDl(&wg)
+	wg.Wait()
+	//计算指标
+	data.RefreshDataFromCalculateAll()
+
+	time.Sleep(2 * time.Second)
+	data.RefreshNotice()
+	return
+}
+
 //刷新基础数据
 func RefreshBaseData(cont context.Context) (err error) {
 	now := time.Now()
@@ -245,6 +254,8 @@ func SyncBaseDataExt(cont context.Context) (err error) {
 	go data.SyncManualDataBase()
 	//同步有色基础数据
 	go data.SyncSmmDataBase()
+	//刷新图表中,指标的最新日期
+	go data.SetChartEdbEndDate()
 	return
 }
 

+ 24 - 15
utils/constants.go

@@ -63,21 +63,30 @@ const (
 
 //数据来源渠道
 const (
-	DATA_SOURCE_THS                 = iota + 1 //同花顺
-	DATA_SOURCE_WIND                           //wind
-	DATA_SOURCE_PB                             //彭博
-	DATA_SOURCE_CALCULATE                      //计算指标
-	DATA_SOURCE_CALCULATE_LJZZY                //累计值转月
-	DATA_SOURCE_CALCULATE_TBZ                  //同比值
-	DATA_SOURCE_CALCULATE_TCZ                  //同差值
-	DATA_SOURCE_CALCULATE_NSZYDPJJS            //N数值移动平均计算
-	DATA_SOURCE_MANUAL                         //手工指标
-	DATA_SOURCE_LZ                             //隆众
-	DATA_SOURCE_YS                             //有色
-	DATA_SOURCE_CALCULATE_HBZ                  //环比值->12
-	DATA_SOURCE_CALCULATE_HCZ                  //环差值->13
-	DATA_SOURCE_CALCULATE_BP                   //变频->14
-	DATA_SOURCE_GL                             //钢联->15
+	DATA_SOURCE_THS                  = iota + 1 //同花顺
+	DATA_SOURCE_WIND                            //wind
+	DATA_SOURCE_PB                              //彭博
+	DATA_SOURCE_CALCULATE                       //计算指标
+	DATA_SOURCE_CALCULATE_LJZZY                 //累计值转月
+	DATA_SOURCE_CALCULATE_TBZ                   //同比值
+	DATA_SOURCE_CALCULATE_TCZ                   //同差值
+	DATA_SOURCE_CALCULATE_NSZYDPJJS             //N数值移动平均计算
+	DATA_SOURCE_MANUAL                          //手工指标
+	DATA_SOURCE_LZ                              //隆众
+	DATA_SOURCE_YS                              //有色
+	DATA_SOURCE_CALCULATE_HBZ                   //环比值->12
+	DATA_SOURCE_CALCULATE_HCZ                   //环差值->13
+	DATA_SOURCE_CALCULATE_BP                    //变频->14
+	DATA_SOURCE_GL                              //钢联->15
+	DATA_SOURCE_ZZ                              //郑商所->16
+	DATA_SOURCE_DL                              //大商所->17
+	DATA_SOURCE_SH                              //上期所->18
+	DATA_SOURCE_CFFEX                           //中金所->19
+	DATA_SOURCE_SHFE                            //上期能源->20
+	DATA_SOURCE_GIE                             //欧洲天然气->21
+	DATA_SOURCE_CALCULATE_TIME_SHIFT            //时间移位->22
+	DATA_SOURCE_CALCULATE_ZJPJ                  //直接拼接->23
+	DATA_SOURCE_CALCULATE_LJZTBPJ               //累计值同比拼接->24
 )
 
 //http://datawind.hzinsights.com:8040/hz_server