Roc 2 年之前
父节点
当前提交
03323ed211
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10 2
      models/edb_data_calculate_hcz.go

+ 10 - 2
models/edb_data_calculate_hcz.go

@@ -234,9 +234,15 @@ func refreshAllCalculateHcz(to orm.TxOrmer, edbInfoId, source int, fromEdbInfo *
 	existDataList := make([]*EdbData, 0)
 	dataTableName := GetEdbDataTableName(source)
 	fmt.Println("dataTableName:", dataTableName)
+
+	var existPars []interface{}
 	sql := `SELECT * FROM %s WHERE edb_info_id=? `
+	if startDate != "" {
+		sql += " AND data_time>=? "
+		existPars = append(existPars, startDate)
+	}
 	sql = fmt.Sprintf(sql, dataTableName)
-	_, err = to.Raw(sql, edbInfoId).QueryRows(&existDataList)
+	_, err = to.Raw(sql, edbInfoId, existPars).QueryRows(&existDataList)
 	if err != nil {
 		return err
 	}
@@ -246,7 +252,7 @@ func refreshAllCalculateHcz(to orm.TxOrmer, edbInfoId, source int, fromEdbInfo *
 		existDataMap[v.DataTime] = v.Value
 		removeDateMap[v.DataTime] = v.DataTime
 	}
-	fmt.Println("existDataMap:", existDataMap)
+	//fmt.Println("existDataMap:", existDataMap)
 	addSql := ` INSERT INTO edb_data_calculate_hcz(edb_info_id,edb_code,data_time,value,create_time,modify_time,data_timestamp) values `
 	var isAdd bool
 	existMap := make(map[string]string)
@@ -263,6 +269,7 @@ func refreshAllCalculateHcz(to orm.TxOrmer, edbInfoId, source int, fromEdbInfo *
 				if _, ok := existMap[existKey]; !ok {
 
 					currentDate, _ := time.Parse(utils.FormatDate, currentItem.DataTime)
+					//fmt.Println(currentDate)
 					timestamp := currentDate.UnixNano() / 1e6
 					timestampStr := fmt.Sprintf("%d", timestamp)
 					val := HczDiv(currentItem.Value, preItem.Value)
@@ -299,6 +306,7 @@ func refreshAllCalculateHcz(to orm.TxOrmer, edbInfoId, source int, fromEdbInfo *
 		}
 	}
 
+	//fmt.Println(removeDateMap)
 	if len(removeDateMap) > 0 {
 		removeDateList := make([]string, 0) //需要移除的日期
 		for k := range removeDateMap {