Răsfoiți Sursa

Merge branch 'master' of http://git.ascrm.cn:3000/scrm/wechat-api

boweniac 7 luni în urmă
părinte
comite
40a3449c2b

+ 10 - 0
desc/wechat/batch_msg.api

@@ -11,6 +11,9 @@ type (
         // 批次号 
         BatchNo  *string `json:"batchNo,optional"`
 
+		// 任务名称
+		TaskName  *string `json:"taskName,optional"`
+
         // 发送方微信ID 
         Fromwxid  *string `json:"fromwxid,optional"`
 
@@ -37,6 +40,10 @@ type (
         // 结束时间 
         StopTime  *int64 `json:"stopTime,optional"`
 
+		// 发送时间
+		SendTime  *int64 `json:"sendTime,optional"`
+		SendTimeStr *string `json:"sendTimeStr,optional"`
+
         // 标签列表
         Labels  []string `json:"labels,optional"`
     }
@@ -69,6 +76,9 @@ type (
 
         // 内容 
         Msg  *string `json:"msg,optional"`
+
+		// 任务名称
+		TaskName  *string `json:"taskName,optional"`
     }
 
     // BatchMsg information response | BatchMsg信息返回体

+ 25 - 3
ent/batchmsg.go

@@ -27,6 +27,8 @@ type BatchMsg struct {
 	Status uint8 `json:"status,omitempty"`
 	// 批次号
 	BatchNo string `json:"batch_no,omitempty"`
+	// 任务名称
+	TaskName string `json:"task_name,omitempty"`
 	// 发送方微信ID
 	Fromwxid string `json:"fromwxid,omitempty"`
 	// 内容
@@ -42,7 +44,9 @@ type BatchMsg struct {
 	// 开始时间
 	StartTime time.Time `json:"start_time,omitempty"`
 	// 结束时间
-	StopTime     time.Time `json:"stop_time,omitempty"`
+	StopTime time.Time `json:"stop_time,omitempty"`
+	// 发送时间
+	SendTime     time.Time `json:"send_time,omitempty"`
 	selectValues sql.SelectValues
 }
 
@@ -53,9 +57,9 @@ func (*BatchMsg) scanValues(columns []string) ([]any, error) {
 		switch columns[i] {
 		case batchmsg.FieldID, batchmsg.FieldStatus, batchmsg.FieldTotal, batchmsg.FieldSuccess, batchmsg.FieldFail:
 			values[i] = new(sql.NullInt64)
-		case batchmsg.FieldBatchNo, batchmsg.FieldFromwxid, batchmsg.FieldMsg, batchmsg.FieldTag:
+		case batchmsg.FieldBatchNo, batchmsg.FieldTaskName, batchmsg.FieldFromwxid, batchmsg.FieldMsg, batchmsg.FieldTag:
 			values[i] = new(sql.NullString)
-		case batchmsg.FieldCreatedAt, batchmsg.FieldUpdatedAt, batchmsg.FieldDeletedAt, batchmsg.FieldStartTime, batchmsg.FieldStopTime:
+		case batchmsg.FieldCreatedAt, batchmsg.FieldUpdatedAt, batchmsg.FieldDeletedAt, batchmsg.FieldStartTime, batchmsg.FieldStopTime, batchmsg.FieldSendTime:
 			values[i] = new(sql.NullTime)
 		default:
 			values[i] = new(sql.UnknownType)
@@ -108,6 +112,12 @@ func (bm *BatchMsg) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				bm.BatchNo = value.String
 			}
+		case batchmsg.FieldTaskName:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field task_name", values[i])
+			} else if value.Valid {
+				bm.TaskName = value.String
+			}
 		case batchmsg.FieldFromwxid:
 			if value, ok := values[i].(*sql.NullString); !ok {
 				return fmt.Errorf("unexpected type %T for field fromwxid", values[i])
@@ -156,6 +166,12 @@ func (bm *BatchMsg) assignValues(columns []string, values []any) error {
 			} else if value.Valid {
 				bm.StopTime = value.Time
 			}
+		case batchmsg.FieldSendTime:
+			if value, ok := values[i].(*sql.NullTime); !ok {
+				return fmt.Errorf("unexpected type %T for field send_time", values[i])
+			} else if value.Valid {
+				bm.SendTime = value.Time
+			}
 		default:
 			bm.selectValues.Set(columns[i], values[i])
 		}
@@ -207,6 +223,9 @@ func (bm *BatchMsg) String() string {
 	builder.WriteString("batch_no=")
 	builder.WriteString(bm.BatchNo)
 	builder.WriteString(", ")
+	builder.WriteString("task_name=")
+	builder.WriteString(bm.TaskName)
+	builder.WriteString(", ")
 	builder.WriteString("fromwxid=")
 	builder.WriteString(bm.Fromwxid)
 	builder.WriteString(", ")
@@ -230,6 +249,9 @@ func (bm *BatchMsg) String() string {
 	builder.WriteString(", ")
 	builder.WriteString("stop_time=")
 	builder.WriteString(bm.StopTime.Format(time.ANSIC))
+	builder.WriteString(", ")
+	builder.WriteString("send_time=")
+	builder.WriteString(bm.SendTime.Format(time.ANSIC))
 	builder.WriteByte(')')
 	return builder.String()
 }

+ 18 - 0
ent/batchmsg/batchmsg.go

@@ -24,6 +24,8 @@ const (
 	FieldStatus = "status"
 	// FieldBatchNo holds the string denoting the batch_no field in the database.
 	FieldBatchNo = "batch_no"
+	// FieldTaskName holds the string denoting the task_name field in the database.
+	FieldTaskName = "task_name"
 	// FieldFromwxid holds the string denoting the fromwxid field in the database.
 	FieldFromwxid = "fromwxid"
 	// FieldMsg holds the string denoting the msg field in the database.
@@ -40,6 +42,8 @@ const (
 	FieldStartTime = "start_time"
 	// FieldStopTime holds the string denoting the stop_time field in the database.
 	FieldStopTime = "stop_time"
+	// FieldSendTime holds the string denoting the send_time field in the database.
+	FieldSendTime = "send_time"
 	// Table holds the table name of the batchmsg in the database.
 	Table = "batch_msg"
 )
@@ -52,6 +56,7 @@ var Columns = []string{
 	FieldDeletedAt,
 	FieldStatus,
 	FieldBatchNo,
+	FieldTaskName,
 	FieldFromwxid,
 	FieldMsg,
 	FieldTag,
@@ -60,6 +65,7 @@ var Columns = []string{
 	FieldFail,
 	FieldStartTime,
 	FieldStopTime,
+	FieldSendTime,
 }
 
 // ValidColumn reports if the column name is valid (part of the table columns).
@@ -86,6 +92,8 @@ var (
 	DefaultUpdatedAt func() time.Time
 	// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
 	UpdateDefaultUpdatedAt func() time.Time
+	// DefaultTaskName holds the default value on creation for the "task_name" field.
+	DefaultTaskName string
 )
 
 // OrderOption defines the ordering options for the BatchMsg queries.
@@ -121,6 +129,11 @@ func ByBatchNo(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldBatchNo, opts...).ToFunc()
 }
 
+// ByTaskName orders the results by the task_name field.
+func ByTaskName(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldTaskName, opts...).ToFunc()
+}
+
 // ByFromwxid orders the results by the fromwxid field.
 func ByFromwxid(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldFromwxid, opts...).ToFunc()
@@ -160,3 +173,8 @@ func ByStartTime(opts ...sql.OrderTermOption) OrderOption {
 func ByStopTime(opts ...sql.OrderTermOption) OrderOption {
 	return sql.OrderByField(FieldStopTime, opts...).ToFunc()
 }
+
+// BySendTime orders the results by the send_time field.
+func BySendTime(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldSendTime, opts...).ToFunc()
+}

+ 135 - 0
ent/batchmsg/where.go

@@ -79,6 +79,11 @@ func BatchNo(v string) predicate.BatchMsg {
 	return predicate.BatchMsg(sql.FieldEQ(FieldBatchNo, v))
 }
 
+// TaskName applies equality check predicate on the "task_name" field. It's identical to TaskNameEQ.
+func TaskName(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldEQ(FieldTaskName, v))
+}
+
 // Fromwxid applies equality check predicate on the "fromwxid" field. It's identical to FromwxidEQ.
 func Fromwxid(v string) predicate.BatchMsg {
 	return predicate.BatchMsg(sql.FieldEQ(FieldFromwxid, v))
@@ -119,6 +124,11 @@ func StopTime(v time.Time) predicate.BatchMsg {
 	return predicate.BatchMsg(sql.FieldEQ(FieldStopTime, v))
 }
 
+// SendTime applies equality check predicate on the "send_time" field. It's identical to SendTimeEQ.
+func SendTime(v time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldEQ(FieldSendTime, v))
+}
+
 // CreatedAtEQ applies the EQ predicate on the "created_at" field.
 func CreatedAtEQ(v time.Time) predicate.BatchMsg {
 	return predicate.BatchMsg(sql.FieldEQ(FieldCreatedAt, v))
@@ -374,6 +384,81 @@ func BatchNoContainsFold(v string) predicate.BatchMsg {
 	return predicate.BatchMsg(sql.FieldContainsFold(FieldBatchNo, v))
 }
 
+// TaskNameEQ applies the EQ predicate on the "task_name" field.
+func TaskNameEQ(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldEQ(FieldTaskName, v))
+}
+
+// TaskNameNEQ applies the NEQ predicate on the "task_name" field.
+func TaskNameNEQ(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldNEQ(FieldTaskName, v))
+}
+
+// TaskNameIn applies the In predicate on the "task_name" field.
+func TaskNameIn(vs ...string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldIn(FieldTaskName, vs...))
+}
+
+// TaskNameNotIn applies the NotIn predicate on the "task_name" field.
+func TaskNameNotIn(vs ...string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldNotIn(FieldTaskName, vs...))
+}
+
+// TaskNameGT applies the GT predicate on the "task_name" field.
+func TaskNameGT(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldGT(FieldTaskName, v))
+}
+
+// TaskNameGTE applies the GTE predicate on the "task_name" field.
+func TaskNameGTE(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldGTE(FieldTaskName, v))
+}
+
+// TaskNameLT applies the LT predicate on the "task_name" field.
+func TaskNameLT(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldLT(FieldTaskName, v))
+}
+
+// TaskNameLTE applies the LTE predicate on the "task_name" field.
+func TaskNameLTE(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldLTE(FieldTaskName, v))
+}
+
+// TaskNameContains applies the Contains predicate on the "task_name" field.
+func TaskNameContains(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldContains(FieldTaskName, v))
+}
+
+// TaskNameHasPrefix applies the HasPrefix predicate on the "task_name" field.
+func TaskNameHasPrefix(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldHasPrefix(FieldTaskName, v))
+}
+
+// TaskNameHasSuffix applies the HasSuffix predicate on the "task_name" field.
+func TaskNameHasSuffix(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldHasSuffix(FieldTaskName, v))
+}
+
+// TaskNameIsNil applies the IsNil predicate on the "task_name" field.
+func TaskNameIsNil() predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldIsNull(FieldTaskName))
+}
+
+// TaskNameNotNil applies the NotNil predicate on the "task_name" field.
+func TaskNameNotNil() predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldNotNull(FieldTaskName))
+}
+
+// TaskNameEqualFold applies the EqualFold predicate on the "task_name" field.
+func TaskNameEqualFold(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldEqualFold(FieldTaskName, v))
+}
+
+// TaskNameContainsFold applies the ContainsFold predicate on the "task_name" field.
+func TaskNameContainsFold(v string) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldContainsFold(FieldTaskName, v))
+}
+
 // FromwxidEQ applies the EQ predicate on the "fromwxid" field.
 func FromwxidEQ(v string) predicate.BatchMsg {
 	return predicate.BatchMsg(sql.FieldEQ(FieldFromwxid, v))
@@ -849,6 +934,56 @@ func StopTimeNotNil() predicate.BatchMsg {
 	return predicate.BatchMsg(sql.FieldNotNull(FieldStopTime))
 }
 
+// SendTimeEQ applies the EQ predicate on the "send_time" field.
+func SendTimeEQ(v time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldEQ(FieldSendTime, v))
+}
+
+// SendTimeNEQ applies the NEQ predicate on the "send_time" field.
+func SendTimeNEQ(v time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldNEQ(FieldSendTime, v))
+}
+
+// SendTimeIn applies the In predicate on the "send_time" field.
+func SendTimeIn(vs ...time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldIn(FieldSendTime, vs...))
+}
+
+// SendTimeNotIn applies the NotIn predicate on the "send_time" field.
+func SendTimeNotIn(vs ...time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldNotIn(FieldSendTime, vs...))
+}
+
+// SendTimeGT applies the GT predicate on the "send_time" field.
+func SendTimeGT(v time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldGT(FieldSendTime, v))
+}
+
+// SendTimeGTE applies the GTE predicate on the "send_time" field.
+func SendTimeGTE(v time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldGTE(FieldSendTime, v))
+}
+
+// SendTimeLT applies the LT predicate on the "send_time" field.
+func SendTimeLT(v time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldLT(FieldSendTime, v))
+}
+
+// SendTimeLTE applies the LTE predicate on the "send_time" field.
+func SendTimeLTE(v time.Time) predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldLTE(FieldSendTime, v))
+}
+
+// SendTimeIsNil applies the IsNil predicate on the "send_time" field.
+func SendTimeIsNil() predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldIsNull(FieldSendTime))
+}
+
+// SendTimeNotNil applies the NotNil predicate on the "send_time" field.
+func SendTimeNotNil() predicate.BatchMsg {
+	return predicate.BatchMsg(sql.FieldNotNull(FieldSendTime))
+}
+
 // And groups predicates with the AND operator between them.
 func And(predicates ...predicate.BatchMsg) predicate.BatchMsg {
 	return predicate.BatchMsg(sql.AndPredicates(predicates...))

+ 160 - 0
ent/batchmsg_create.go

@@ -92,6 +92,20 @@ func (bmc *BatchMsgCreate) SetNillableBatchNo(s *string) *BatchMsgCreate {
 	return bmc
 }
 
+// SetTaskName sets the "task_name" field.
+func (bmc *BatchMsgCreate) SetTaskName(s string) *BatchMsgCreate {
+	bmc.mutation.SetTaskName(s)
+	return bmc
+}
+
+// SetNillableTaskName sets the "task_name" field if the given value is not nil.
+func (bmc *BatchMsgCreate) SetNillableTaskName(s *string) *BatchMsgCreate {
+	if s != nil {
+		bmc.SetTaskName(*s)
+	}
+	return bmc
+}
+
 // SetFromwxid sets the "fromwxid" field.
 func (bmc *BatchMsgCreate) SetFromwxid(s string) *BatchMsgCreate {
 	bmc.mutation.SetFromwxid(s)
@@ -204,6 +218,20 @@ func (bmc *BatchMsgCreate) SetNillableStopTime(t *time.Time) *BatchMsgCreate {
 	return bmc
 }
 
+// SetSendTime sets the "send_time" field.
+func (bmc *BatchMsgCreate) SetSendTime(t time.Time) *BatchMsgCreate {
+	bmc.mutation.SetSendTime(t)
+	return bmc
+}
+
+// SetNillableSendTime sets the "send_time" field if the given value is not nil.
+func (bmc *BatchMsgCreate) SetNillableSendTime(t *time.Time) *BatchMsgCreate {
+	if t != nil {
+		bmc.SetSendTime(*t)
+	}
+	return bmc
+}
+
 // SetID sets the "id" field.
 func (bmc *BatchMsgCreate) SetID(u uint64) *BatchMsgCreate {
 	bmc.mutation.SetID(u)
@@ -261,6 +289,10 @@ func (bmc *BatchMsgCreate) defaults() error {
 		v := batchmsg.DefaultUpdatedAt()
 		bmc.mutation.SetUpdatedAt(v)
 	}
+	if _, ok := bmc.mutation.TaskName(); !ok {
+		v := batchmsg.DefaultTaskName
+		bmc.mutation.SetTaskName(v)
+	}
 	return nil
 }
 
@@ -325,6 +357,10 @@ func (bmc *BatchMsgCreate) createSpec() (*BatchMsg, *sqlgraph.CreateSpec) {
 		_spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
 		_node.BatchNo = value
 	}
+	if value, ok := bmc.mutation.TaskName(); ok {
+		_spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
+		_node.TaskName = value
+	}
 	if value, ok := bmc.mutation.Fromwxid(); ok {
 		_spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
 		_node.Fromwxid = value
@@ -357,6 +393,10 @@ func (bmc *BatchMsgCreate) createSpec() (*BatchMsg, *sqlgraph.CreateSpec) {
 		_spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
 		_node.StopTime = value
 	}
+	if value, ok := bmc.mutation.SendTime(); ok {
+		_spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
+		_node.SendTime = value
+	}
 	return _node, _spec
 }
 
@@ -481,6 +521,24 @@ func (u *BatchMsgUpsert) ClearBatchNo() *BatchMsgUpsert {
 	return u
 }
 
+// SetTaskName sets the "task_name" field.
+func (u *BatchMsgUpsert) SetTaskName(v string) *BatchMsgUpsert {
+	u.Set(batchmsg.FieldTaskName, v)
+	return u
+}
+
+// UpdateTaskName sets the "task_name" field to the value that was provided on create.
+func (u *BatchMsgUpsert) UpdateTaskName() *BatchMsgUpsert {
+	u.SetExcluded(batchmsg.FieldTaskName)
+	return u
+}
+
+// ClearTaskName clears the value of the "task_name" field.
+func (u *BatchMsgUpsert) ClearTaskName() *BatchMsgUpsert {
+	u.SetNull(batchmsg.FieldTaskName)
+	return u
+}
+
 // SetFromwxid sets the "fromwxid" field.
 func (u *BatchMsgUpsert) SetFromwxid(v string) *BatchMsgUpsert {
 	u.Set(batchmsg.FieldFromwxid, v)
@@ -643,6 +701,24 @@ func (u *BatchMsgUpsert) ClearStopTime() *BatchMsgUpsert {
 	return u
 }
 
+// SetSendTime sets the "send_time" field.
+func (u *BatchMsgUpsert) SetSendTime(v time.Time) *BatchMsgUpsert {
+	u.Set(batchmsg.FieldSendTime, v)
+	return u
+}
+
+// UpdateSendTime sets the "send_time" field to the value that was provided on create.
+func (u *BatchMsgUpsert) UpdateSendTime() *BatchMsgUpsert {
+	u.SetExcluded(batchmsg.FieldSendTime)
+	return u
+}
+
+// ClearSendTime clears the value of the "send_time" field.
+func (u *BatchMsgUpsert) ClearSendTime() *BatchMsgUpsert {
+	u.SetNull(batchmsg.FieldSendTime)
+	return u
+}
+
 // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
 // Using this option is equivalent to using:
 //
@@ -778,6 +854,27 @@ func (u *BatchMsgUpsertOne) ClearBatchNo() *BatchMsgUpsertOne {
 	})
 }
 
+// SetTaskName sets the "task_name" field.
+func (u *BatchMsgUpsertOne) SetTaskName(v string) *BatchMsgUpsertOne {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.SetTaskName(v)
+	})
+}
+
+// UpdateTaskName sets the "task_name" field to the value that was provided on create.
+func (u *BatchMsgUpsertOne) UpdateTaskName() *BatchMsgUpsertOne {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.UpdateTaskName()
+	})
+}
+
+// ClearTaskName clears the value of the "task_name" field.
+func (u *BatchMsgUpsertOne) ClearTaskName() *BatchMsgUpsertOne {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.ClearTaskName()
+	})
+}
+
 // SetFromwxid sets the "fromwxid" field.
 func (u *BatchMsgUpsertOne) SetFromwxid(v string) *BatchMsgUpsertOne {
 	return u.Update(func(s *BatchMsgUpsert) {
@@ -967,6 +1064,27 @@ func (u *BatchMsgUpsertOne) ClearStopTime() *BatchMsgUpsertOne {
 	})
 }
 
+// SetSendTime sets the "send_time" field.
+func (u *BatchMsgUpsertOne) SetSendTime(v time.Time) *BatchMsgUpsertOne {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.SetSendTime(v)
+	})
+}
+
+// UpdateSendTime sets the "send_time" field to the value that was provided on create.
+func (u *BatchMsgUpsertOne) UpdateSendTime() *BatchMsgUpsertOne {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.UpdateSendTime()
+	})
+}
+
+// ClearSendTime clears the value of the "send_time" field.
+func (u *BatchMsgUpsertOne) ClearSendTime() *BatchMsgUpsertOne {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.ClearSendTime()
+	})
+}
+
 // Exec executes the query.
 func (u *BatchMsgUpsertOne) Exec(ctx context.Context) error {
 	if len(u.create.conflict) == 0 {
@@ -1268,6 +1386,27 @@ func (u *BatchMsgUpsertBulk) ClearBatchNo() *BatchMsgUpsertBulk {
 	})
 }
 
+// SetTaskName sets the "task_name" field.
+func (u *BatchMsgUpsertBulk) SetTaskName(v string) *BatchMsgUpsertBulk {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.SetTaskName(v)
+	})
+}
+
+// UpdateTaskName sets the "task_name" field to the value that was provided on create.
+func (u *BatchMsgUpsertBulk) UpdateTaskName() *BatchMsgUpsertBulk {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.UpdateTaskName()
+	})
+}
+
+// ClearTaskName clears the value of the "task_name" field.
+func (u *BatchMsgUpsertBulk) ClearTaskName() *BatchMsgUpsertBulk {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.ClearTaskName()
+	})
+}
+
 // SetFromwxid sets the "fromwxid" field.
 func (u *BatchMsgUpsertBulk) SetFromwxid(v string) *BatchMsgUpsertBulk {
 	return u.Update(func(s *BatchMsgUpsert) {
@@ -1457,6 +1596,27 @@ func (u *BatchMsgUpsertBulk) ClearStopTime() *BatchMsgUpsertBulk {
 	})
 }
 
+// SetSendTime sets the "send_time" field.
+func (u *BatchMsgUpsertBulk) SetSendTime(v time.Time) *BatchMsgUpsertBulk {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.SetSendTime(v)
+	})
+}
+
+// UpdateSendTime sets the "send_time" field to the value that was provided on create.
+func (u *BatchMsgUpsertBulk) UpdateSendTime() *BatchMsgUpsertBulk {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.UpdateSendTime()
+	})
+}
+
+// ClearSendTime clears the value of the "send_time" field.
+func (u *BatchMsgUpsertBulk) ClearSendTime() *BatchMsgUpsertBulk {
+	return u.Update(func(s *BatchMsgUpsert) {
+		s.ClearSendTime()
+	})
+}
+
 // Exec executes the query.
 func (u *BatchMsgUpsertBulk) Exec(ctx context.Context) error {
 	if u.create.err != nil {

+ 104 - 0
ent/batchmsg_update.go

@@ -101,6 +101,26 @@ func (bmu *BatchMsgUpdate) ClearBatchNo() *BatchMsgUpdate {
 	return bmu
 }
 
+// SetTaskName sets the "task_name" field.
+func (bmu *BatchMsgUpdate) SetTaskName(s string) *BatchMsgUpdate {
+	bmu.mutation.SetTaskName(s)
+	return bmu
+}
+
+// SetNillableTaskName sets the "task_name" field if the given value is not nil.
+func (bmu *BatchMsgUpdate) SetNillableTaskName(s *string) *BatchMsgUpdate {
+	if s != nil {
+		bmu.SetTaskName(*s)
+	}
+	return bmu
+}
+
+// ClearTaskName clears the value of the "task_name" field.
+func (bmu *BatchMsgUpdate) ClearTaskName() *BatchMsgUpdate {
+	bmu.mutation.ClearTaskName()
+	return bmu
+}
+
 // SetFromwxid sets the "fromwxid" field.
 func (bmu *BatchMsgUpdate) SetFromwxid(s string) *BatchMsgUpdate {
 	bmu.mutation.SetFromwxid(s)
@@ -282,6 +302,26 @@ func (bmu *BatchMsgUpdate) ClearStopTime() *BatchMsgUpdate {
 	return bmu
 }
 
+// SetSendTime sets the "send_time" field.
+func (bmu *BatchMsgUpdate) SetSendTime(t time.Time) *BatchMsgUpdate {
+	bmu.mutation.SetSendTime(t)
+	return bmu
+}
+
+// SetNillableSendTime sets the "send_time" field if the given value is not nil.
+func (bmu *BatchMsgUpdate) SetNillableSendTime(t *time.Time) *BatchMsgUpdate {
+	if t != nil {
+		bmu.SetSendTime(*t)
+	}
+	return bmu
+}
+
+// ClearSendTime clears the value of the "send_time" field.
+func (bmu *BatchMsgUpdate) ClearSendTime() *BatchMsgUpdate {
+	bmu.mutation.ClearSendTime()
+	return bmu
+}
+
 // Mutation returns the BatchMsgMutation object of the builder.
 func (bmu *BatchMsgUpdate) Mutation() *BatchMsgMutation {
 	return bmu.mutation
@@ -362,6 +402,12 @@ func (bmu *BatchMsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if bmu.mutation.BatchNoCleared() {
 		_spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
 	}
+	if value, ok := bmu.mutation.TaskName(); ok {
+		_spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
+	}
+	if bmu.mutation.TaskNameCleared() {
+		_spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
+	}
 	if value, ok := bmu.mutation.Fromwxid(); ok {
 		_spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
 	}
@@ -419,6 +465,12 @@ func (bmu *BatchMsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
 	if bmu.mutation.StopTimeCleared() {
 		_spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
 	}
+	if value, ok := bmu.mutation.SendTime(); ok {
+		_spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
+	}
+	if bmu.mutation.SendTimeCleared() {
+		_spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
+	}
 	if n, err = sqlgraph.UpdateNodes(ctx, bmu.driver, _spec); err != nil {
 		if _, ok := err.(*sqlgraph.NotFoundError); ok {
 			err = &NotFoundError{batchmsg.Label}
@@ -512,6 +564,26 @@ func (bmuo *BatchMsgUpdateOne) ClearBatchNo() *BatchMsgUpdateOne {
 	return bmuo
 }
 
+// SetTaskName sets the "task_name" field.
+func (bmuo *BatchMsgUpdateOne) SetTaskName(s string) *BatchMsgUpdateOne {
+	bmuo.mutation.SetTaskName(s)
+	return bmuo
+}
+
+// SetNillableTaskName sets the "task_name" field if the given value is not nil.
+func (bmuo *BatchMsgUpdateOne) SetNillableTaskName(s *string) *BatchMsgUpdateOne {
+	if s != nil {
+		bmuo.SetTaskName(*s)
+	}
+	return bmuo
+}
+
+// ClearTaskName clears the value of the "task_name" field.
+func (bmuo *BatchMsgUpdateOne) ClearTaskName() *BatchMsgUpdateOne {
+	bmuo.mutation.ClearTaskName()
+	return bmuo
+}
+
 // SetFromwxid sets the "fromwxid" field.
 func (bmuo *BatchMsgUpdateOne) SetFromwxid(s string) *BatchMsgUpdateOne {
 	bmuo.mutation.SetFromwxid(s)
@@ -693,6 +765,26 @@ func (bmuo *BatchMsgUpdateOne) ClearStopTime() *BatchMsgUpdateOne {
 	return bmuo
 }
 
+// SetSendTime sets the "send_time" field.
+func (bmuo *BatchMsgUpdateOne) SetSendTime(t time.Time) *BatchMsgUpdateOne {
+	bmuo.mutation.SetSendTime(t)
+	return bmuo
+}
+
+// SetNillableSendTime sets the "send_time" field if the given value is not nil.
+func (bmuo *BatchMsgUpdateOne) SetNillableSendTime(t *time.Time) *BatchMsgUpdateOne {
+	if t != nil {
+		bmuo.SetSendTime(*t)
+	}
+	return bmuo
+}
+
+// ClearSendTime clears the value of the "send_time" field.
+func (bmuo *BatchMsgUpdateOne) ClearSendTime() *BatchMsgUpdateOne {
+	bmuo.mutation.ClearSendTime()
+	return bmuo
+}
+
 // Mutation returns the BatchMsgMutation object of the builder.
 func (bmuo *BatchMsgUpdateOne) Mutation() *BatchMsgMutation {
 	return bmuo.mutation
@@ -803,6 +895,12 @@ func (bmuo *BatchMsgUpdateOne) sqlSave(ctx context.Context) (_node *BatchMsg, er
 	if bmuo.mutation.BatchNoCleared() {
 		_spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
 	}
+	if value, ok := bmuo.mutation.TaskName(); ok {
+		_spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
+	}
+	if bmuo.mutation.TaskNameCleared() {
+		_spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
+	}
 	if value, ok := bmuo.mutation.Fromwxid(); ok {
 		_spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
 	}
@@ -860,6 +958,12 @@ func (bmuo *BatchMsgUpdateOne) sqlSave(ctx context.Context) (_node *BatchMsg, er
 	if bmuo.mutation.StopTimeCleared() {
 		_spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
 	}
+	if value, ok := bmuo.mutation.SendTime(); ok {
+		_spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
+	}
+	if bmuo.mutation.SendTimeCleared() {
+		_spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
+	}
 	_node = &BatchMsg{config: bmuo.config}
 	_spec.Assign = _node.assignValues
 	_spec.ScanValues = _node.scanValues

+ 2 - 0
ent/migrate/schema.go

@@ -43,6 +43,7 @@ var (
 		{Name: "deleted_at", Type: field.TypeTime, Nullable: true, Comment: "Delete Time | 删除日期"},
 		{Name: "status", Type: field.TypeUint8, Nullable: true, Comment: "状态 0 未开始 1 开始发送 2 发送完成 3 发送中止"},
 		{Name: "batch_no", Type: field.TypeString, Unique: true, Nullable: true, Comment: "批次号"},
+		{Name: "task_name", Type: field.TypeString, Nullable: true, Comment: "任务名称", Default: ""},
 		{Name: "fromwxid", Type: field.TypeString, Nullable: true, Comment: "发送方微信ID"},
 		{Name: "msg", Type: field.TypeString, Nullable: true, Comment: "内容"},
 		{Name: "tag", Type: field.TypeString, Nullable: true, Comment: "发送规则 all 全部 tag1,tag2 按tag发送"},
@@ -51,6 +52,7 @@ var (
 		{Name: "fail", Type: field.TypeInt32, Nullable: true, Comment: "失败数量"},
 		{Name: "start_time", Type: field.TypeTime, Nullable: true, Comment: "开始时间"},
 		{Name: "stop_time", Type: field.TypeTime, Nullable: true, Comment: "结束时间"},
+		{Name: "send_time", Type: field.TypeTime, Nullable: true, Comment: "发送时间"},
 	}
 	// BatchMsgTable holds the schema information for the "batch_msg" table.
 	BatchMsgTable = &schema.Table{

+ 147 - 1
ent/mutation.go

@@ -1070,6 +1070,7 @@ type BatchMsgMutation struct {
 	status        *uint8
 	addstatus     *int8
 	batch_no      *string
+	task_name     *string
 	fromwxid      *string
 	msg           *string
 	tag           *string
@@ -1081,6 +1082,7 @@ type BatchMsgMutation struct {
 	addfail       *int32
 	start_time    *time.Time
 	stop_time     *time.Time
+	send_time     *time.Time
 	clearedFields map[string]struct{}
 	done          bool
 	oldValue      func(context.Context) (*BatchMsg, error)
@@ -1431,6 +1433,55 @@ func (m *BatchMsgMutation) ResetBatchNo() {
 	delete(m.clearedFields, batchmsg.FieldBatchNo)
 }
 
+// SetTaskName sets the "task_name" field.
+func (m *BatchMsgMutation) SetTaskName(s string) {
+	m.task_name = &s
+}
+
+// TaskName returns the value of the "task_name" field in the mutation.
+func (m *BatchMsgMutation) TaskName() (r string, exists bool) {
+	v := m.task_name
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldTaskName returns the old "task_name" field's value of the BatchMsg entity.
+// If the BatchMsg object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *BatchMsgMutation) OldTaskName(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldTaskName is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldTaskName requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldTaskName: %w", err)
+	}
+	return oldValue.TaskName, nil
+}
+
+// ClearTaskName clears the value of the "task_name" field.
+func (m *BatchMsgMutation) ClearTaskName() {
+	m.task_name = nil
+	m.clearedFields[batchmsg.FieldTaskName] = struct{}{}
+}
+
+// TaskNameCleared returns if the "task_name" field was cleared in this mutation.
+func (m *BatchMsgMutation) TaskNameCleared() bool {
+	_, ok := m.clearedFields[batchmsg.FieldTaskName]
+	return ok
+}
+
+// ResetTaskName resets all changes to the "task_name" field.
+func (m *BatchMsgMutation) ResetTaskName() {
+	m.task_name = nil
+	delete(m.clearedFields, batchmsg.FieldTaskName)
+}
+
 // SetFromwxid sets the "fromwxid" field.
 func (m *BatchMsgMutation) SetFromwxid(s string) {
 	m.fromwxid = &s
@@ -1886,6 +1937,55 @@ func (m *BatchMsgMutation) ResetStopTime() {
 	delete(m.clearedFields, batchmsg.FieldStopTime)
 }
 
+// SetSendTime sets the "send_time" field.
+func (m *BatchMsgMutation) SetSendTime(t time.Time) {
+	m.send_time = &t
+}
+
+// SendTime returns the value of the "send_time" field in the mutation.
+func (m *BatchMsgMutation) SendTime() (r time.Time, exists bool) {
+	v := m.send_time
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldSendTime returns the old "send_time" field's value of the BatchMsg entity.
+// If the BatchMsg object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *BatchMsgMutation) OldSendTime(ctx context.Context) (v time.Time, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldSendTime is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldSendTime requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldSendTime: %w", err)
+	}
+	return oldValue.SendTime, nil
+}
+
+// ClearSendTime clears the value of the "send_time" field.
+func (m *BatchMsgMutation) ClearSendTime() {
+	m.send_time = nil
+	m.clearedFields[batchmsg.FieldSendTime] = struct{}{}
+}
+
+// SendTimeCleared returns if the "send_time" field was cleared in this mutation.
+func (m *BatchMsgMutation) SendTimeCleared() bool {
+	_, ok := m.clearedFields[batchmsg.FieldSendTime]
+	return ok
+}
+
+// ResetSendTime resets all changes to the "send_time" field.
+func (m *BatchMsgMutation) ResetSendTime() {
+	m.send_time = nil
+	delete(m.clearedFields, batchmsg.FieldSendTime)
+}
+
 // Where appends a list predicates to the BatchMsgMutation builder.
 func (m *BatchMsgMutation) Where(ps ...predicate.BatchMsg) {
 	m.predicates = append(m.predicates, ps...)
@@ -1920,7 +2020,7 @@ func (m *BatchMsgMutation) Type() string {
 // order to get all numeric fields that were incremented/decremented, call
 // AddedFields().
 func (m *BatchMsgMutation) Fields() []string {
-	fields := make([]string, 0, 13)
+	fields := make([]string, 0, 15)
 	if m.created_at != nil {
 		fields = append(fields, batchmsg.FieldCreatedAt)
 	}
@@ -1936,6 +2036,9 @@ func (m *BatchMsgMutation) Fields() []string {
 	if m.batch_no != nil {
 		fields = append(fields, batchmsg.FieldBatchNo)
 	}
+	if m.task_name != nil {
+		fields = append(fields, batchmsg.FieldTaskName)
+	}
 	if m.fromwxid != nil {
 		fields = append(fields, batchmsg.FieldFromwxid)
 	}
@@ -1960,6 +2063,9 @@ func (m *BatchMsgMutation) Fields() []string {
 	if m.stop_time != nil {
 		fields = append(fields, batchmsg.FieldStopTime)
 	}
+	if m.send_time != nil {
+		fields = append(fields, batchmsg.FieldSendTime)
+	}
 	return fields
 }
 
@@ -1978,6 +2084,8 @@ func (m *BatchMsgMutation) Field(name string) (ent.Value, bool) {
 		return m.Status()
 	case batchmsg.FieldBatchNo:
 		return m.BatchNo()
+	case batchmsg.FieldTaskName:
+		return m.TaskName()
 	case batchmsg.FieldFromwxid:
 		return m.Fromwxid()
 	case batchmsg.FieldMsg:
@@ -1994,6 +2102,8 @@ func (m *BatchMsgMutation) Field(name string) (ent.Value, bool) {
 		return m.StartTime()
 	case batchmsg.FieldStopTime:
 		return m.StopTime()
+	case batchmsg.FieldSendTime:
+		return m.SendTime()
 	}
 	return nil, false
 }
@@ -2013,6 +2123,8 @@ func (m *BatchMsgMutation) OldField(ctx context.Context, name string) (ent.Value
 		return m.OldStatus(ctx)
 	case batchmsg.FieldBatchNo:
 		return m.OldBatchNo(ctx)
+	case batchmsg.FieldTaskName:
+		return m.OldTaskName(ctx)
 	case batchmsg.FieldFromwxid:
 		return m.OldFromwxid(ctx)
 	case batchmsg.FieldMsg:
@@ -2029,6 +2141,8 @@ func (m *BatchMsgMutation) OldField(ctx context.Context, name string) (ent.Value
 		return m.OldStartTime(ctx)
 	case batchmsg.FieldStopTime:
 		return m.OldStopTime(ctx)
+	case batchmsg.FieldSendTime:
+		return m.OldSendTime(ctx)
 	}
 	return nil, fmt.Errorf("unknown BatchMsg field %s", name)
 }
@@ -2073,6 +2187,13 @@ func (m *BatchMsgMutation) SetField(name string, value ent.Value) error {
 		}
 		m.SetBatchNo(v)
 		return nil
+	case batchmsg.FieldTaskName:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetTaskName(v)
+		return nil
 	case batchmsg.FieldFromwxid:
 		v, ok := value.(string)
 		if !ok {
@@ -2129,6 +2250,13 @@ func (m *BatchMsgMutation) SetField(name string, value ent.Value) error {
 		}
 		m.SetStopTime(v)
 		return nil
+	case batchmsg.FieldSendTime:
+		v, ok := value.(time.Time)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetSendTime(v)
+		return nil
 	}
 	return fmt.Errorf("unknown BatchMsg field %s", name)
 }
@@ -2219,6 +2347,9 @@ func (m *BatchMsgMutation) ClearedFields() []string {
 	if m.FieldCleared(batchmsg.FieldBatchNo) {
 		fields = append(fields, batchmsg.FieldBatchNo)
 	}
+	if m.FieldCleared(batchmsg.FieldTaskName) {
+		fields = append(fields, batchmsg.FieldTaskName)
+	}
 	if m.FieldCleared(batchmsg.FieldFromwxid) {
 		fields = append(fields, batchmsg.FieldFromwxid)
 	}
@@ -2243,6 +2374,9 @@ func (m *BatchMsgMutation) ClearedFields() []string {
 	if m.FieldCleared(batchmsg.FieldStopTime) {
 		fields = append(fields, batchmsg.FieldStopTime)
 	}
+	if m.FieldCleared(batchmsg.FieldSendTime) {
+		fields = append(fields, batchmsg.FieldSendTime)
+	}
 	return fields
 }
 
@@ -2266,6 +2400,9 @@ func (m *BatchMsgMutation) ClearField(name string) error {
 	case batchmsg.FieldBatchNo:
 		m.ClearBatchNo()
 		return nil
+	case batchmsg.FieldTaskName:
+		m.ClearTaskName()
+		return nil
 	case batchmsg.FieldFromwxid:
 		m.ClearFromwxid()
 		return nil
@@ -2290,6 +2427,9 @@ func (m *BatchMsgMutation) ClearField(name string) error {
 	case batchmsg.FieldStopTime:
 		m.ClearStopTime()
 		return nil
+	case batchmsg.FieldSendTime:
+		m.ClearSendTime()
+		return nil
 	}
 	return fmt.Errorf("unknown BatchMsg nullable field %s", name)
 }
@@ -2313,6 +2453,9 @@ func (m *BatchMsgMutation) ResetField(name string) error {
 	case batchmsg.FieldBatchNo:
 		m.ResetBatchNo()
 		return nil
+	case batchmsg.FieldTaskName:
+		m.ResetTaskName()
+		return nil
 	case batchmsg.FieldFromwxid:
 		m.ResetFromwxid()
 		return nil
@@ -2337,6 +2480,9 @@ func (m *BatchMsgMutation) ResetField(name string) error {
 	case batchmsg.FieldStopTime:
 		m.ResetStopTime()
 		return nil
+	case batchmsg.FieldSendTime:
+		m.ResetSendTime()
+		return nil
 	}
 	return fmt.Errorf("unknown BatchMsg field %s", name)
 }

+ 4 - 0
ent/runtime/runtime.go

@@ -92,6 +92,10 @@ func init() {
 	batchmsg.DefaultUpdatedAt = batchmsgDescUpdatedAt.Default.(func() time.Time)
 	// batchmsg.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
 	batchmsg.UpdateDefaultUpdatedAt = batchmsgDescUpdatedAt.UpdateDefault.(func() time.Time)
+	// batchmsgDescTaskName is the schema descriptor for task_name field.
+	batchmsgDescTaskName := batchmsgFields[2].Descriptor()
+	// batchmsg.DefaultTaskName holds the default value on creation for the task_name field.
+	batchmsg.DefaultTaskName = batchmsgDescTaskName.Default.(string)
 	contactMixin := schema.Contact{}.Mixin()
 	contactMixinHooks2 := contactMixin[2].Hooks()
 	contact.Hooks[0] = contactMixinHooks2[0]

+ 3 - 1
ent/schema/batch_msg.go

@@ -19,6 +19,7 @@ func (BatchMsg) Fields() []ent.Field {
 	return []ent.Field{
 		field.Uint8("status").Optional().Comment("状态 0 未开始 1 开始发送 2 发送完成 3 发送中止"),
 		field.String("batch_no").Optional().Unique().Comment("批次号"),
+		field.String("task_name").Optional().Default("").Comment("任务名称"),
 		field.String("fromwxid").Optional().Comment("发送方微信ID"),
 		field.String("msg").Optional().Comment("内容"),
 		field.String("tag").Optional().Comment("发送规则 all 全部 tag1,tag2 按tag发送"),
@@ -26,7 +27,8 @@ func (BatchMsg) Fields() []ent.Field {
 		field.Int32("success").Optional().Comment("成功数量"),
 		field.Int32("fail").Optional().Comment("失败数量"),
 		field.Time("start_time").Optional().Comment("开始时间"),
-		field.Time("stop_time").Optional().Comment("结束时间")}
+		field.Time("stop_time").Optional().Comment("结束时间"),
+		field.Time("send_time").Optional().Comment("发送时间")}
 }
 func (BatchMsg) Mixin() []ent.Mixin {
 	return []ent.Mixin{

+ 48 - 0
ent/set_not_nil.go

@@ -296,6 +296,30 @@ func (bm *BatchMsgCreate) SetNotNilBatchNo(value *string) *BatchMsgCreate {
 }
 
 // set field if value's pointer is not nil.
+func (bm *BatchMsgUpdate) SetNotNilTaskName(value *string) *BatchMsgUpdate {
+	if value != nil {
+		return bm.SetTaskName(*value)
+	}
+	return bm
+}
+
+// set field if value's pointer is not nil.
+func (bm *BatchMsgUpdateOne) SetNotNilTaskName(value *string) *BatchMsgUpdateOne {
+	if value != nil {
+		return bm.SetTaskName(*value)
+	}
+	return bm
+}
+
+// set field if value's pointer is not nil.
+func (bm *BatchMsgCreate) SetNotNilTaskName(value *string) *BatchMsgCreate {
+	if value != nil {
+		return bm.SetTaskName(*value)
+	}
+	return bm
+}
+
+// set field if value's pointer is not nil.
 func (bm *BatchMsgUpdate) SetNotNilFromwxid(value *string) *BatchMsgUpdate {
 	if value != nil {
 		return bm.SetFromwxid(*value)
@@ -488,6 +512,30 @@ func (bm *BatchMsgCreate) SetNotNilStopTime(value *time.Time) *BatchMsgCreate {
 }
 
 // set field if value's pointer is not nil.
+func (bm *BatchMsgUpdate) SetNotNilSendTime(value *time.Time) *BatchMsgUpdate {
+	if value != nil {
+		return bm.SetSendTime(*value)
+	}
+	return bm
+}
+
+// set field if value's pointer is not nil.
+func (bm *BatchMsgUpdateOne) SetNotNilSendTime(value *time.Time) *BatchMsgUpdateOne {
+	if value != nil {
+		return bm.SetSendTime(*value)
+	}
+	return bm
+}
+
+// set field if value's pointer is not nil.
+func (bm *BatchMsgCreate) SetNotNilSendTime(value *time.Time) *BatchMsgCreate {
+	if value != nil {
+		return bm.SetSendTime(*value)
+	}
+	return bm
+}
+
+// set field if value's pointer is not nil.
 func (c *ContactUpdate) SetNotNilUpdatedAt(value *time.Time) *ContactUpdate {
 	if value != nil {
 		return c.SetUpdatedAt(*value)

+ 78 - 2
internal/logic/batch_msg/create_batch_msg_logic.go

@@ -2,8 +2,11 @@ package batch_msg
 
 import (
 	"context"
+	"encoding/json"
+	"errors"
 	"strings"
 	"time"
+	"wechat-api/ent/custom_types"
 
 	"wechat-api/ent"
 	"wechat-api/ent/contact"
@@ -43,7 +46,7 @@ func (l *CreateBatchMsgLogic) CreateBatchMsg(req *types.BatchMsgInfo) (*types.Ba
 		}
 	}
 
-	l.Logger.Infof("CreateBatchMsgLogic: %v", req)
+	l.Logger.Infof("CreateBatchMsgLogic: %v", *req)
 
 	startTime := time.Now()
 	// req.StartTimeStr 不为nil并且不为空
@@ -58,11 +61,54 @@ func (l *CreateBatchMsgLogic) CreateBatchMsg(req *types.BatchMsgInfo) (*types.Ba
 		}
 	}
 
+	// 定时发送时间
+	var sendTime time.Time
+	if req.SendTimeStr != nil && *req.SendTimeStr != "" {
+		var err error
+		sendTime, err = time.Parse("2006-01-02 15:04:05", *req.SendTimeStr)
+		if err != nil {
+			// 处理错误,例如打印错误并返回
+			l.Logger.Errorf("时间字符串转换错误: %v", err)
+			return nil, err
+		}
+	}
+
+	// 发送内容处理下,json_decode
+	var err error
+	var msgArray []custom_types.Action
+
+	if req.Msg != nil && *req.Msg != "" {
+		err = json.Unmarshal([]byte(*req.Msg), &msgArray)
+		if err != nil {
+			return nil, errors.New("解析JSON失败")
+		}
+	}
+
+	var actionMessage []custom_types.Action
+	if len(msgArray) > 0 {
+		actionMessage = make([]custom_types.Action, len(msgArray))
+		for i, msg := range msgArray {
+			if msg.Type == 1 {
+				actionMessage[i] = custom_types.Action{
+					Type:    msg.Type,
+					Content: msg.Content,
+				}
+			} else {
+				actionMessage[i] = custom_types.Action{
+					Type:    msg.Type,
+					Content: msg.Content,
+					Meta: &custom_types.Meta{
+						Filename: msg.Meta.Filename,
+					},
+				}
+			}
+		}
+	}
+
 	tagstring := strings.Join(req.Labels, ",")
 	req.Tag = &tagstring
 
 	userlist := make([]*ent.Contact, 0)
-	var err error
 
 	if all {
 		// 获取 contact 表中  wx_wxid 等于 req.Fromwxid 的 type 为1或2的数据
@@ -102,6 +148,9 @@ func (l *CreateBatchMsgLogic) CreateBatchMsg(req *types.BatchMsgInfo) (*types.Ba
 	uuid := uuidx.NewUUID()
 	batchNo := uuid.String()
 
+	// 开始事务
+	tx, err := l.svcCtx.DB.Tx(context.Background())
+
 	_, err = l.svcCtx.DB.BatchMsg.Create().
 		SetNotNilBatchNo(&batchNo).
 		SetNotNilFromwxid(req.Fromwxid).
@@ -109,11 +158,38 @@ func (l *CreateBatchMsgLogic) CreateBatchMsg(req *types.BatchMsgInfo) (*types.Ba
 		SetNotNilTag(req.Tag).
 		SetTotal(total).
 		SetNotNilStartTime(&startTime).
+		SetNotNilSendTime(&sendTime).
 		Save(l.ctx)
 
 	if err != nil {
+		_ = tx.Rollback()
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
+	// 批量记录信息到 message_records 表里
+	for _, user := range userlist {
+		// 每个用户的所有 信息 组合到一个数组里然后批量插入,减少DB的压力
+		bulkCreate := make([]*ent.MessageRecordsCreate, 0)
+		for _, msg := range actionMessage {
+			bulkCreate = append(bulkCreate, l.svcCtx.DB.MessageRecords.Create().
+				SetStatus(1).
+				SetNotNilBotWxid(req.Fromwxid).
+				SetNotNilContactID(&user.ID).
+				SetNotNilContactType(&user.Type).
+				SetNotNilContactWxid(&user.Wxid).
+				SetNotNilContentType(&msg.Type).
+				SetNotNilContent(&msg.Content).
+				SetNotNilMeta(msg.Meta).
+				SetSendTime(sendTime),
+			)
+		}
+		err = l.svcCtx.DB.MessageRecords.CreateBulk(bulkCreate...).Exec(l.ctx)
+		if err != nil {
+			_ = tx.Rollback()
+			return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+		}
+	}
+	_ = tx.Commit()
+
 	return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
 }

+ 24 - 23
internal/logic/batch_msg/get_batch_msg_by_id_logic.go

@@ -7,7 +7,7 @@ import (
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -34,27 +34,28 @@ func (l *GetBatchMsgByIdLogic) GetBatchMsgById(req *types.IDReq) (*types.BatchMs
 	}
 
 	return &types.BatchMsgInfoResp{
-	    BaseDataInfo: types.BaseDataInfo{
-            Code: 0,
-            Msg:  errormsg.Success,
-        },
-        Data: types.BatchMsgInfo{
-            BaseIDInfo:    types.BaseIDInfo{
-				Id:          &data.ID,
-				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
-            },
-			Status:	&data.Status,
-			BatchNo:	&data.BatchNo,
-			Fromwxid:	&data.Fromwxid,
-			Msg:	&data.Msg,
-			Tag:	&data.Tag,
-			Total:	&data.Total,
-			Success:	&data.Success,
-			Fail:	&data.Fail,
-			StartTime:	pointy.GetUnixMilliPointer(data.StartTime.UnixMilli()),
-			StopTime:	pointy.GetUnixMilliPointer(data.StopTime.UnixMilli()),
-        },
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.BatchMsgInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:    &data.Status,
+			BatchNo:   &data.BatchNo,
+			TaskName:  &data.TaskName,
+			Fromwxid:  &data.Fromwxid,
+			Msg:       &data.Msg,
+			Tag:       &data.Tag,
+			Total:     &data.Total,
+			Success:   &data.Success,
+			Fail:      &data.Fail,
+			StartTime: pointy.GetUnixMilliPointer(data.StartTime.UnixMilli()),
+			StopTime:  pointy.GetUnixMilliPointer(data.StopTime.UnixMilli()),
+			SendTime:  pointy.GetUnixMilliPointer(data.SendTime.UnixMilli()),
+		},
 	}, nil
 }
-

+ 23 - 18
internal/logic/batch_msg/get_batch_msg_list_logic.go

@@ -9,7 +9,7 @@ import (
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
 
-    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -40,6 +40,9 @@ func (l *GetBatchMsgListLogic) GetBatchMsgList(req *types.BatchMsgListReq) (*typ
 	if req.Msg != nil {
 		predicates = append(predicates, batchmsg.MsgContains(*req.Msg))
 	}
+	if req.TaskName != nil {
+		predicates = append(predicates, batchmsg.TaskNameContains(*req.TaskName))
+	}
 	data, err := l.svcCtx.DB.BatchMsg.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {
@@ -52,23 +55,25 @@ func (l *GetBatchMsgListLogic) GetBatchMsgList(req *types.BatchMsgListReq) (*typ
 
 	for _, v := range data.List {
 		resp.Data.Data = append(resp.Data.Data,
-		types.BatchMsgInfo{
-			BaseIDInfo:    types.BaseIDInfo{
-				Id:          &v.ID,
-				CreatedAt:    pointy.GetPointer(v.CreatedAt.UnixMilli()),
-				UpdatedAt:    pointy.GetPointer(v.UpdatedAt.UnixMilli()),
-            },
-			Status:	&v.Status,
-			BatchNo:	&v.BatchNo,
-			Fromwxid:	&v.Fromwxid,
-			Msg:	&v.Msg,
-			Tag:	&v.Tag,
-			Total:	&v.Total,
-			Success:	&v.Success,
-			Fail:	&v.Fail,
-			StartTime:	pointy.GetUnixMilliPointer(v.StartTime.UnixMilli()),
-			StopTime:	pointy.GetUnixMilliPointer(v.StopTime.UnixMilli()),
-		})
+			types.BatchMsgInfo{
+				BaseIDInfo: types.BaseIDInfo{
+					Id:        &v.ID,
+					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
+					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+				},
+				Status:    &v.Status,
+				BatchNo:   &v.BatchNo,
+				TaskName:  &v.TaskName,
+				Fromwxid:  &v.Fromwxid,
+				Msg:       &v.Msg,
+				Tag:       &v.Tag,
+				Total:     &v.Total,
+				Success:   &v.Success,
+				Fail:      &v.Fail,
+				StartTime: pointy.GetUnixMilliPointer(v.StartTime.UnixMilli()),
+				StopTime:  pointy.GetUnixMilliPointer(v.StopTime.UnixMilli()),
+				SendTime:  pointy.GetUnixMilliPointer(v.SendTime.UnixMilli()),
+			})
 	}
 
 	return resp, nil

+ 7 - 0
internal/types/types.go

@@ -1208,6 +1208,8 @@ type BatchMsgInfo struct {
 	Status *uint8 `json:"status,optional"`
 	// 批次号
 	BatchNo *string `json:"batchNo,optional"`
+	// 任务名称
+	TaskName *string `json:"taskName,optional"`
 	// 发送方微信ID
 	Fromwxid *string `json:"fromwxid,optional"`
 	// 内容
@@ -1225,6 +1227,9 @@ type BatchMsgInfo struct {
 	StartTimeStr *string `json:"startTimeStr,optional"`
 	// 结束时间
 	StopTime *int64 `json:"stopTime,optional"`
+	// 发送时间
+	SendTime    *int64  `json:"sendTime,optional"`
+	SendTimeStr *string `json:"sendTimeStr,optional"`
 	// 标签列表
 	Labels []string `json:"labels,optional"`
 }
@@ -1255,6 +1260,8 @@ type BatchMsgListReq struct {
 	Fromwxid *string `json:"fromwxid,optional"`
 	// 内容
 	Msg *string `json:"msg,optional"`
+	// 任务名称
+	TaskName *string `json:"taskName,optional"`
 }
 
 // BatchMsg information response | BatchMsg信息返回体