| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 | package svcimport (	"golib/features/mo"	"golib/infra/ii")type Operator interface {	Build() mo.D}// OptionUpdate 更新文档选项, 通常情况下// https://www.mongodb.com/docs/manual/reference/operator/update-field/type OptionUpdate struct {	CurrentDate mo.D	Set         mo.D}// SetCurrentDate 设置更新时间// TODO 也可以设置子 map key 的时间, 详情参见 example: https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/#examplefunc (o *OptionUpdate) SetCurrentDate() {	o.CurrentDate = mo.D{		{Key: "$currentDate", Value: mo.D{			{Key: ii.LastModified, Value: true},		}},	}}// SetSet 设置需要更新的字段////	$set: {//	       "cancellation.reason": "user request",//	       status: "D"//	    }func (o *OptionUpdate) SetSet(d any) {	o.Set = mo.D{{Key: "$set", Value: d}}}func (o *OptionUpdate) Build() mo.D {	op := mo.D{}	if o.CurrentDate != nil {		op = append(op, o.CurrentDate...)	}	if o.Set != nil {		op = append(op, o.Set...)	}	return op}
 |