Files
bj_power/bj_power_mes/ent/alert_create.go
T
SunYF 5c3b747a20 feat: 新增预警与附件模块,优化工位派工功能
1. 新增预警规则、预警消息、业务附件数据库表与CRUD逻辑
2. 为拧紧记录添加审核人、审核时间字段及审核留痕功能
3. 优化产线点位类型与编号描述,更新工位组合下发菜单名称为工艺路线派工
4. 新增上传文件获取原文件名与大小的工具方法
5. 在系统管理菜单新增预警中心与附件中心入口
2026-09-14 16:31:08 +08:00

431 lines
12 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/alert"
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// AlertCreate is the builder for creating a Alert entity.
type AlertCreate struct {
config
mutation *AlertMutation
hooks []Hook
}
// SetRuleId sets the "ruleId" field.
func (_c *AlertCreate) SetRuleId(v int) *AlertCreate {
_c.mutation.SetRuleId(v)
return _c
}
// SetNillableRuleId sets the "ruleId" field if the given value is not nil.
func (_c *AlertCreate) SetNillableRuleId(v *int) *AlertCreate {
if v != nil {
_c.SetRuleId(*v)
}
return _c
}
// SetType sets the "type" field.
func (_c *AlertCreate) SetType(v string) *AlertCreate {
_c.mutation.SetType(v)
return _c
}
// SetTitle sets the "title" field.
func (_c *AlertCreate) SetTitle(v string) *AlertCreate {
_c.mutation.SetTitle(v)
return _c
}
// SetContent sets the "content" field.
func (_c *AlertCreate) SetContent(v string) *AlertCreate {
_c.mutation.SetContent(v)
return _c
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (_c *AlertCreate) SetNillableContent(v *string) *AlertCreate {
if v != nil {
_c.SetContent(*v)
}
return _c
}
// SetRefType sets the "refType" field.
func (_c *AlertCreate) SetRefType(v string) *AlertCreate {
_c.mutation.SetRefType(v)
return _c
}
// SetNillableRefType sets the "refType" field if the given value is not nil.
func (_c *AlertCreate) SetNillableRefType(v *string) *AlertCreate {
if v != nil {
_c.SetRefType(*v)
}
return _c
}
// SetRefId sets the "refId" field.
func (_c *AlertCreate) SetRefId(v string) *AlertCreate {
_c.mutation.SetRefId(v)
return _c
}
// SetNillableRefId sets the "refId" field if the given value is not nil.
func (_c *AlertCreate) SetNillableRefId(v *string) *AlertCreate {
if v != nil {
_c.SetRefId(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *AlertCreate) SetStatus(v string) *AlertCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *AlertCreate) SetNillableStatus(v *string) *AlertCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetReceiver sets the "receiver" field.
func (_c *AlertCreate) SetReceiver(v string) *AlertCreate {
_c.mutation.SetReceiver(v)
return _c
}
// SetNillableReceiver sets the "receiver" field if the given value is not nil.
func (_c *AlertCreate) SetNillableReceiver(v *string) *AlertCreate {
if v != nil {
_c.SetReceiver(*v)
}
return _c
}
// SetCreatedAt sets the "createdAt" field.
func (_c *AlertCreate) SetCreatedAt(v time.Time) *AlertCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
func (_c *AlertCreate) SetNillableCreatedAt(v *time.Time) *AlertCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *AlertCreate) SetID(v int) *AlertCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the AlertMutation object of the builder.
func (_c *AlertCreate) Mutation() *AlertMutation {
return _c.mutation
}
// Save creates the Alert in the database.
func (_c *AlertCreate) Save(ctx context.Context) (*Alert, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *AlertCreate) SaveX(ctx context.Context) *Alert {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AlertCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AlertCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *AlertCreate) defaults() {
if _, ok := _c.mutation.RuleId(); !ok {
v := alert.DefaultRuleId
_c.mutation.SetRuleId(v)
}
if _, ok := _c.mutation.Content(); !ok {
v := alert.DefaultContent
_c.mutation.SetContent(v)
}
if _, ok := _c.mutation.RefType(); !ok {
v := alert.DefaultRefType
_c.mutation.SetRefType(v)
}
if _, ok := _c.mutation.RefId(); !ok {
v := alert.DefaultRefId
_c.mutation.SetRefId(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := alert.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.Receiver(); !ok {
v := alert.DefaultReceiver
_c.mutation.SetReceiver(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := alert.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *AlertCreate) check() error {
if _, ok := _c.mutation.RuleId(); !ok {
return &ValidationError{Name: "ruleId", err: errors.New(`ent: missing required field "Alert.ruleId"`)}
}
if _, ok := _c.mutation.GetType(); !ok {
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Alert.type"`)}
}
if v, ok := _c.mutation.GetType(); ok {
if err := alert.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Alert.type": %w`, err)}
}
}
if _, ok := _c.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Alert.title"`)}
}
if v, ok := _c.mutation.Title(); ok {
if err := alert.TitleValidator(v); err != nil {
return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Alert.title": %w`, err)}
}
}
if _, ok := _c.mutation.Content(); !ok {
return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Alert.content"`)}
}
if v, ok := _c.mutation.Content(); ok {
if err := alert.ContentValidator(v); err != nil {
return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "Alert.content": %w`, err)}
}
}
if _, ok := _c.mutation.RefType(); !ok {
return &ValidationError{Name: "refType", err: errors.New(`ent: missing required field "Alert.refType"`)}
}
if v, ok := _c.mutation.RefType(); ok {
if err := alert.RefTypeValidator(v); err != nil {
return &ValidationError{Name: "refType", err: fmt.Errorf(`ent: validator failed for field "Alert.refType": %w`, err)}
}
}
if _, ok := _c.mutation.RefId(); !ok {
return &ValidationError{Name: "refId", err: errors.New(`ent: missing required field "Alert.refId"`)}
}
if v, ok := _c.mutation.RefId(); ok {
if err := alert.RefIdValidator(v); err != nil {
return &ValidationError{Name: "refId", err: fmt.Errorf(`ent: validator failed for field "Alert.refId": %w`, err)}
}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Alert.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := alert.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Alert.status": %w`, err)}
}
}
if _, ok := _c.mutation.Receiver(); !ok {
return &ValidationError{Name: "receiver", err: errors.New(`ent: missing required field "Alert.receiver"`)}
}
if v, ok := _c.mutation.Receiver(); ok {
if err := alert.ReceiverValidator(v); err != nil {
return &ValidationError{Name: "receiver", err: fmt.Errorf(`ent: validator failed for field "Alert.receiver": %w`, err)}
}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "Alert.createdAt"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := alert.IDValidator(v); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "Alert.id": %w`, err)}
}
}
return nil
}
func (_c *AlertCreate) sqlSave(ctx context.Context) (*Alert, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int(id)
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *AlertCreate) createSpec() (*Alert, *sqlgraph.CreateSpec) {
var (
_node = &Alert{config: _c.config}
_spec = sqlgraph.NewCreateSpec(alert.Table, sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.RuleId(); ok {
_spec.SetField(alert.FieldRuleId, field.TypeInt, value)
_node.RuleId = value
}
if value, ok := _c.mutation.GetType(); ok {
_spec.SetField(alert.FieldType, field.TypeString, value)
_node.Type = value
}
if value, ok := _c.mutation.Title(); ok {
_spec.SetField(alert.FieldTitle, field.TypeString, value)
_node.Title = value
}
if value, ok := _c.mutation.Content(); ok {
_spec.SetField(alert.FieldContent, field.TypeString, value)
_node.Content = value
}
if value, ok := _c.mutation.RefType(); ok {
_spec.SetField(alert.FieldRefType, field.TypeString, value)
_node.RefType = value
}
if value, ok := _c.mutation.RefId(); ok {
_spec.SetField(alert.FieldRefId, field.TypeString, value)
_node.RefId = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(alert.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.Receiver(); ok {
_spec.SetField(alert.FieldReceiver, field.TypeString, value)
_node.Receiver = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(alert.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
return _node, _spec
}
// AlertCreateBulk is the builder for creating many Alert entities in bulk.
type AlertCreateBulk struct {
config
err error
builders []*AlertCreate
}
// Save creates the Alert entities in the database.
func (_c *AlertCreateBulk) Save(ctx context.Context) ([]*Alert, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Alert, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*AlertMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *AlertCreateBulk) SaveX(ctx context.Context) []*Alert {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AlertCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AlertCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}