|
@@ -124,35 +124,51 @@ func RefreshEdbDataByLz(edbInfoId int, edbCode, startDate, endDate string) (err
|
|
|
|
|
|
lzDataList, err := GetLzSurveyDataByTradeCode(condition, pars)
|
|
|
|
|
|
+ //获取已存在指标所有数据
|
|
|
+ existDataList := make([]*EdbDataBase, 0)
|
|
|
+ dataTableName := GetEdbDataTableName(utils.DATA_SOURCE_LZ)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
addSql := ` INSERT INTO edb_data_lz(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
|
|
|
var isAdd bool
|
|
|
+ addExistMap := make(map[string]string)
|
|
|
for _, v := range lzDataList {
|
|
|
item := v
|
|
|
- count, err := GetEdbDataLzByCodeAndDate(edbCode, v.DataTime)
|
|
|
- if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- return err
|
|
|
- }
|
|
|
- if count <= 0 {
|
|
|
- nowStr := time.Now().Format(utils.FormatDateTime)
|
|
|
- eDate := item.DataTime
|
|
|
- sValue := item.InputValue
|
|
|
- dataTime, err := time.Parse(utils.FormatDate, eDate)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- timestamp := dataTime.UnixNano() / 1e6
|
|
|
- timeStr := fmt.Sprintf("%d", timestamp)
|
|
|
- addSql += "("
|
|
|
- addSql += edbInfoIdStr + "," + "'" + edbCode + "'" + "," + "'" + eDate + "'" + "," + sValue + "," + "'" + nowStr + "'" +
|
|
|
- "," + "'" + nowStr + "'" + "," + "1" + "," + "'" + timeStr + "'"
|
|
|
- addSql += "),"
|
|
|
- isAdd = true
|
|
|
- } else {
|
|
|
- err = ModifyEdbDataLz(int64(edbInfoId), v.DataTime, v.InputValue)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ if _, ok := addExistMap[v.DataTime]; !ok {
|
|
|
+ if existVal, existOk := existDataMap[v.DataTime]; !existOk {
|
|
|
+ eDate := item.DataTime
|
|
|
+ sValue := item.InputValue
|
|
|
+ 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 {
|
|
|
+ if existVal != item.InputValue {
|
|
|
+ sql := ` UPDATE %s SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
|
|
|
+ sql = fmt.Sprintf(sql, dataTableName)
|
|
|
+ _, err = o.Raw(sql, item.InputValue, edbInfoId, v.DataTime).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ addExistMap[v.DataTime] = v.InputValue
|
|
|
}
|
|
|
if isAdd {
|
|
|
addSql = strings.TrimRight(addSql, ",")
|
|
@@ -161,16 +177,5 @@ func RefreshEdbDataByLz(edbInfoId int, edbCode, startDate, endDate string) (err
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- maxAndMinItem, err := GetEdbInfoMaxAndMinInfo(utils.DATA_SOURCE_LZ, edbCode)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- if maxAndMinItem != nil {
|
|
|
- err = ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
return
|
|
|
}
|