|
@@ -16,7 +16,7 @@ import (
|
|
|
// EdbDataInsertConfig 指标数据插入配置表
|
|
|
type EdbDataInsertConfig struct {
|
|
|
//EdbInfoId int `orm:"column(edb_info_id);pk" description:"指标id"`
|
|
|
- EdbInfoId int `gorm:"column:edb_info_id;primaryKey" description:"指标id"`
|
|
|
+ EdbInfoId int `gorm:"primaryKey;autoIncrement:false;column:edb_info_id" description:"指标id"`
|
|
|
Date time.Time `description:"插入的日期"`
|
|
|
Value string `description:"插入的值"`
|
|
|
RealDate time.Time `description:"实际数据的值日期"`
|
|
@@ -97,7 +97,7 @@ func CreateEdbDataInsertConfigAndData(edbInfo *EdbInfo, date time.Time, value st
|
|
|
err = nil
|
|
|
|
|
|
// 如果是没有配置,那么就需要添加配置
|
|
|
- if item == nil {
|
|
|
+ if item == nil || item.EdbInfoId <= 0 {
|
|
|
var currLatestDate time.Time
|
|
|
currLatestDateStr := edbInfo.LatestDate // 实际日期
|
|
|
if currLatestDateStr != `` && currLatestDateStr != `0000-00-00` {
|
|
@@ -201,7 +201,7 @@ func updateInsertConfigValueByMysql(to *gorm.DB, edbInfo *EdbInfo, oldConfigDate
|
|
|
sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? AND data_time = ?`
|
|
|
sql = fmt.Sprintf(sql, tableName)
|
|
|
sql = utils.ReplaceDriverKeywords("", sql)
|
|
|
- err = to.Raw(sql, tableName, edbInfo.EdbInfoId, oldConfigDate.Format(utils.FormatDate)).First(&edbDateData).Error
|
|
|
+ err = to.Raw(sql, edbInfo.EdbInfoId, oldConfigDate.Format(utils.FormatDate)).First(&edbDateData).Error
|
|
|
//err = to.Raw(sql, edbInfo.EdbInfoId, oldConfigDate.Format(utils.FormatDate)).QueryRow(&edbDateData)
|
|
|
if err != nil && !utils.IsErrNoRow(err) {
|
|
|
return
|
|
@@ -211,7 +211,7 @@ func updateInsertConfigValueByMysql(to *gorm.DB, edbInfo *EdbInfo, oldConfigDate
|
|
|
|
|
|
// 如果是没有历史数据,那么就需要增加数据
|
|
|
if edbDateData == nil {
|
|
|
- addSql := ` INSERT INTO %s (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) VALUES ( %d, "%s", "%s", "%s", now(), now(), %s) `
|
|
|
+ addSql := ` INSERT INTO %s (edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) VALUES ( %d, '%s', '%s', '%s', now(), now(), %s) `
|
|
|
addSql = fmt.Sprintf(addSql, tableName, edbInfo.EdbInfoId, edbInfo.EdbCode, dateStr, saveValue, timeStr)
|
|
|
addSql = utils.ReplaceDriverKeywords("", addSql)
|
|
|
err = to.Exec(addSql).Error
|
|
@@ -233,7 +233,7 @@ func updateInsertConfigValueByMysql(to *gorm.DB, edbInfo *EdbInfo, oldConfigDate
|
|
|
//_, err = to.Raw(deleteSql).Exec()
|
|
|
err = to.Exec(deleteSql).Error
|
|
|
} else {
|
|
|
- updateSql := `UPDATE %s SET data_time = "%s", value = "%s", modify_time= now(), data_timestamp= %s WHERE edb_data_id = %d;`
|
|
|
+ updateSql := `UPDATE %s SET data_time = '%s', value = '%s', modify_time= now(), data_timestamp= %s WHERE edb_data_id = %d;`
|
|
|
updateSql = utils.ReplaceDriverKeywords("", updateSql)
|
|
|
updateSql = fmt.Sprintf(updateSql, tableName, dateStr, saveValue, timeStr, edbDateData.EdbDataId)
|
|
|
//_, err = to.Raw(updateSql).Exec()
|