diff --git a/app/utils/excute/dbExecute.go b/app/utils/excute/dbExecute.go index 6a89845..1f003bf 100644 --- a/app/utils/excute/dbExecute.go +++ b/app/utils/excute/dbExecute.go @@ -7,6 +7,7 @@ import ( "gorm.io/gorm" "reflect" "strings" + "time" ) type ExecuteDb struct { @@ -58,12 +59,31 @@ func (db *ExecuteDb) ExecuteWriteV2(readData []map[string]interface{}, execute s func (db *ExecuteDb) replaceExecuteString(execute string, rowData map[string]interface{}) string { executeString := execute for key, value := range rowData { + formatValue := FormatValueData(value) key := fmt.Sprintf("${%s}", key) - executeString = strings.Replace(executeString, key, fmt.Sprintf("%v", value), -1) + executeString = strings.Replace(executeString, key, fmt.Sprintf("%v", formatValue), -1) } return executeString } +func FormatValueData(v interface{}) interface{} { + var format interface{} + switch v.(type) { + case nil: + format = "NULL" + case time.Time: + format = fmt.Sprintf("'%v'", v.(time.Time).Format("2006-01-02 15:04:05")) + + case []uint8: + format = fmt.Sprintf("'%v'", string(v.([]uint8))) + case string: + format = fmt.Sprintf("'%v'", v) + default: + format = v + } + return format +} + func FilterReadData(data *[]map[string]interface{}, matchJson string) (filteredData []map[string]interface{}, err error) { if matchJson == "" { return *data, nil diff --git a/go.mod b/go.mod index 75c45cf..9fb368b 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/go-sql-driver/mysql v1.7.0 github.com/golang-jwt/jwt/v4 v4.5.0 github.com/golang/protobuf v1.5.4 - github.com/jinzhu/copier v0.4.0 github.com/nacos-group/nacos-sdk-go/v2 v2.2.5 github.com/nats-io/nats.go v1.9.1 github.com/openzipkin/zipkin-go v0.2.2