修复通道提取接口权限与数据映射问题

This commit is contained in:
2025-12-01 12:43:29 +08:00
parent 299ce821d5
commit a024c38375
11 changed files with 124 additions and 198 deletions

View File

@@ -1,74 +0,0 @@
package orm
import (
"database/sql"
"database/sql/driver"
"time"
)
type LocalDateTime time.Time
var formats = []string{
"2006-01-02 15:04:05.999999999-07:00",
"2006-01-02T15:04:05.999999999-07:00",
"2006-01-02 15:04:05.999999999",
"2006-01-02T15:04:05.999999999",
"2006-01-02 15:04:05",
"2006-01-02T15:04:05",
"2006-01-02 15:04",
"2006-01-02T15:04",
"2006-01-02",
}
func (ldt *LocalDateTime) Scan(value any) (err error) {
var t time.Time
if strValue, ok := value.(string); ok {
var timeValue time.Time
for _, format := range formats {
timeValue, err = time.Parse(format, strValue)
if err == nil {
t = timeValue
break
}
}
t = timeValue
} else {
nullTime := &sql.NullTime{}
err = nullTime.Scan(value)
if err != nil {
return err
}
if nullTime == nil {
return nil
}
t = nullTime.Time
}
*ldt = LocalDateTime(time.Date(
t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), time.Local,
))
return
}
func (ldt LocalDateTime) Value() (driver.Value, error) {
return time.Time(ldt).Local(), nil
}
func (ldt LocalDateTime) GormDataType() string {
return "ldt"
}
func (ldt LocalDateTime) GobEncode() ([]byte, error) {
return time.Time(ldt).GobEncode()
}
func (ldt *LocalDateTime) GobDecode(b []byte) error {
return (*time.Time)(ldt).GobDecode(b)
}
func (ldt LocalDateTime) MarshalJSON() ([]byte, error) {
return time.Time(ldt).MarshalJSON()
}
func (ldt *LocalDateTime) UnmarshalJSON(b []byte) error {
return (*time.Time)(ldt).UnmarshalJSON(b)
}

View File

@@ -1,24 +0,0 @@
package orm
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
type Slice[T any] struct {
Arr []T
}
func (s Slice[T]) Value() (driver.Value, error) {
return json.Marshal(s)
}
func (s *Slice[T]) Scan(value any) error {
switch value := value.(type) {
case []byte:
return json.Unmarshal(value, s)
default:
return fmt.Errorf("不支持的类型: %T", value)
}
}