| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 | package svcimport (	"fmt"	"time"	"golib/v4/features/mo"	"golib/v4/infra/ii")type Row struct {	mo.D}//goland:noinspection ALLfunc (c *Row) Clone() Row {	r := make(mo.D, len(c.D))	for i, v := range c.D {		r[i] = v	}	return Row{D: r}}//goland:noinspection ALLfunc (c *Row) ID() mo.ObjectID {	return c.ObjectID(mo.OID)}//goland:noinspection ALLfunc (c *Row) Any(k string) any {	v, _ := c.Get(k)	return v}//goland:noinspection ALLfunc (c *Row) Double(k string) float64 {	v, ok := c.Get(k)	if !ok {		return 0	}	return v.(float64)}//goland:noinspection ALLfunc (c *Row) Strings(k string) string {	v, ok := c.Get(k)	if !ok {		return ""	}	return v.(string)}//goland:noinspection ALLfunc (c *Row) Object(k string) Row {	v, ok := c.Get(k)	if !ok {		return Row{}	}	return Row{D: v.(mo.D)}}//goland:noinspection ALLfunc (c *Row) ObjectTo(k string, val any) error {	v, ok := c.Get(k)	if !ok {		return fmt.Errorf("field %v not found in Row", k)	}	return mo.Decode(v, val)}//goland:noinspection ALLfunc (c *Row) Array(k string) mo.A {	v, ok := c.Get(k)	if !ok {		return mo.A{}	}	return v.(mo.A)}//goland:noinspection ALLfunc (c *Row) Binary(k string) mo.Binary {	v, ok := c.Get(k)	if !ok {		return mo.Binary{}	}	return v.(mo.Binary)}//goland:noinspection ALLfunc (c *Row) ObjectID(k string) mo.ObjectID {	v, ok := c.Get(k)	if !ok {		return mo.ObjectID{}	}	return v.(mo.ObjectID)}//goland:noinspection ALLfunc (c *Row) Boolean(k string) bool {	v, ok := c.Get(k)	if !ok {		return false	}	return v.(bool)}//goland:noinspection ALLfunc (c *Row) Date(k string) mo.DateTime {	v, ok := c.Get(k)	if !ok {		return mo.DateTime(0)	}	return v.(mo.DateTime)}//goland:noinspection ALLfunc (c *Row) Int32(k string) int32 {	v, ok := c.Get(k)	if !ok {		return 0	}	return v.(int32)}//goland:noinspection ALLfunc (c *Row) Int64(k string) int64 {	v, ok := c.Get(k)	if !ok {		return 0	}	return v.(int64)}//goland:noinspection ALLfunc (c *Row) Has(k string) bool {	v, ok := c.Get(k)	if !ok {		return false	}	return v != nil}//goland:noinspection ALLfunc (c *Row) Range(f func(i int, e mo.E) bool) {	for i, e := range c.D {		if !f(i, e) {			return		}	}}//goland:noinspection ALLfunc (c *Row) ToM() mo.M {	r := make(mo.M, len(c.D))	c.Range(func(i int, e mo.E) bool {		r[e.Key] = e.Value		return true	})	return r}//goland:noinspection ALLfunc (c *Row) CopyToSet(updater *mo.Updater) {	c.Range(func(_ int, e mo.E) bool {		updater.Set(e.Key, e.Value)		return true	})}//goland:noinspection ALLfunc (c *Row) Get(k string) (any, bool) {	for _, e := range c.D {		if e.Key == k {			return e.Value, true		}	}	return nil, false}//goland:noinspection ALLfunc (c *Row) Add(k string, v any) {	c.D = append(c.D, mo.E{Key: k, Value: v})}//goland:noinspection ALLfunc (c *Row) Set(k string, v any) {	set := false	c.Range(func(i int, e mo.E) bool {		if e.Key == k {			c.D[i].Value = v			set = true			return false		}		return true	})	if !set {		c.Add(k, v)	}}//goland:noinspection ALLfunc (c *Row) Del(k string) {	for i, e := range c.D {		if e.Key == k {			c.D = append(c.D[:i], c.D[i+1:]...)		}	}}//goland:noinspection ALLfunc (c *Row) CreationTime() time.Time {	if creat := c.Date(ii.CreationTime); creat > 0 {		return creat.Time().Local()	}	return time.Time{}}//goland:noinspection ALLfunc (c *Row) LastModified() time.Time {	if last := c.Date(ii.LastModified); last > 0 {		return last.Time().Local()	}	return c.CreationTime()}//goland:noinspection ALLfunc (c Row) MarshalJSON() ([]byte, error) {	row := c.Clone()	if row.Has(ii.CreationTime) {		row.Set(ii.CreationTime, c.CreationTime().Format(time.DateTime))	}	if row.Has(ii.LastModified) {		row.Set(ii.LastModified, c.LastModified().Format(time.DateTime))	}	return row.D.MarshalJSON()}//goland:noinspection ALLfunc (c *Row) UnmarshalBSON(data []byte) error {	return mo.Unmarshal(data, &c.D)}//goland:noinspection ALLfunc (c Row) MarshalBSON() ([]byte, error) {	return mo.Marshal(c.D)}
 |