diff --git a/bj_power_wms/e2e_scope_dist.py b/bj_power_wms/e2e_scope_dist.py new file mode 100644 index 0000000..9304d52 --- /dev/null +++ b/bj_power_wms/e2e_scope_dist.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +"""端到端验证:问题四(备料台账无单选全部) + 问题六(盘点范围 + 物料分布)""" +import json, urllib.request, urllib.parse, urllib.error + +BASE = "http://127.0.0.1:8902" +TOKEN = None + +def req(method, path, payload=None, params=None): + url = BASE + path + if params: + qs = urllib.parse.urlencode({k: v for k, v in params.items() if v not in (None, "")}) + if qs: + url += "?" + qs + data = json.dumps(payload).encode() if payload is not None else None + r = urllib.request.Request(url, data=data, method=method) + r.add_header("Content-Type", "application/json") + if TOKEN: + r.add_header("Authorization", "Bearer " + TOKEN) + try: + with urllib.request.urlopen(r, timeout=20) as resp: + return json.loads(resp.read().decode()) + except urllib.error.HTTPError as e: + return {"_http": e.code, "_body": e.read().decode()[:300]} + +def login(): + global TOKEN + d = req("POST", "/api/auth/login", {"username": "admin", "password": "123456"}) + TOKEN = d.get("data", {}).get("token") + assert TOKEN, f"登录失败: {d}" + print("✓ 登录成功 admin") + +passed = [] +def check(name, cond, extra=""): + passed.append(bool(cond)) + print(("✓ " if cond else "✗ ") + name + (f" {extra}" if extra and not cond else "")) + +def main(): + login() + # ---------- 问题四:备料台账无单号查全部 ---------- + d = req("GET", "/api/ledger/query", params={"page": 1, "pageSize": 20}) + t4 = d.get("data", {}) or d + check("ledger/query 无 orderNo 返回 total+list", "list" in t4 and "total" in t4, + f"got {list(t4.keys())}") + + # ---------- 问题六:盘点范围按物料过滤 ---------- + # 先看库存有哪些物料可盘点,选一个真实物料 + st = req("GET", "/api/stock/query", params={"page": 1, "pageSize": 10}) + stock_data = st.get("data", {}) or st + rows = stock_data.get("list") or [] + if rows: + mat = rows[0]["materialCode"] + # 按该物料发起盘点 + d = req("POST", "/api/stocktake/start", {"operator": "e2e", "materialCodes": [mat]}) + data = d.get("data", {}) or d + check("startStocktake 按物料过滤成功", bool(data.get("stocktakeNo")), + f"got {data}") + check("按物料盘点 totalTargets>0", data.get("totalTargets", 0) > 0, + f"totalTargets={data.get('totalTargets')}") + # 按类型过滤发起 + d2 = req("POST", "/api/stocktake/start", {"operator": "e2e", "manageMode": 1}) + data2 = d2.get("data", {}) or d2 + check("startStocktake 按类型(结构件)成功", bool(data2.get("stocktakeNo")), + f"got {data2}") + else: + check("stock/query 有数据(需先造数才能验盘点范围)", False, "库存为空") + + # ---------- 问题六:物料分布数据源(聚合含 zoneCode) ---------- + d = req("GET", "/api/stock/query", params={"page": 1, "pageSize": 50}) + dist = d.get("data", {}) or d + dl = dist.get("list") or [] + check("stock/query 返回 list(分布图数据源)", len(dl) > 0, f"len={len(dl)}") + if dl: + r0 = dl[0] + check("聚合行含 zoneCode/materialCode/totalQty", + all(k in r0 for k in ("zoneCode", "materialCode", "totalQty")), + f"keys={list(r0.keys())}") + + print("\n==== 结果:%d/%d 通过 ====" % (sum(passed), len(passed))) + return all(passed) + +if __name__ == "__main__": + ok = main() + raise SystemExit(0 if ok else 1) \ No newline at end of file diff --git a/bj_power_wms/ent/client.go b/bj_power_wms/ent/client.go index 1da877e..e52ab4d 100644 --- a/bj_power_wms/ent/client.go +++ b/bj_power_wms/ent/client.go @@ -20,7 +20,8 @@ import ( "bj_power_wms/ent/ordermaterialledger" "bj_power_wms/ent/outbounddetail" "bj_power_wms/ent/outboundorder" - "bj_power_wms/ent/packagebox" + "bj_power_wms/ent/permission" + "bj_power_wms/ent/role" "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" @@ -55,8 +56,10 @@ type Client struct { OutboundDetail *OutboundDetailClient // OutboundOrder is the client for interacting with the OutboundOrder builders. OutboundOrder *OutboundOrderClient - // PackageBox is the client for interacting with the PackageBox builders. - PackageBox *PackageBoxClient + // Permission is the client for interacting with the Permission builders. + Permission *PermissionClient + // Role is the client for interacting with the Role builders. + Role *RoleClient // SemiFinished is the client for interacting with the SemiFinished builders. SemiFinished *SemiFinishedClient // StocktakeItem is the client for interacting with the StocktakeItem builders. @@ -87,7 +90,8 @@ func (c *Client) init() { c.OrderMaterialLedger = NewOrderMaterialLedgerClient(c.config) c.OutboundDetail = NewOutboundDetailClient(c.config) c.OutboundOrder = NewOutboundOrderClient(c.config) - c.PackageBox = NewPackageBoxClient(c.config) + c.Permission = NewPermissionClient(c.config) + c.Role = NewRoleClient(c.config) c.SemiFinished = NewSemiFinishedClient(c.config) c.StocktakeItem = NewStocktakeItemClient(c.config) c.StocktakeOrder = NewStocktakeOrderClient(c.config) @@ -194,7 +198,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { OrderMaterialLedger: NewOrderMaterialLedgerClient(cfg), OutboundDetail: NewOutboundDetailClient(cfg), OutboundOrder: NewOutboundOrderClient(cfg), - PackageBox: NewPackageBoxClient(cfg), + Permission: NewPermissionClient(cfg), + Role: NewRoleClient(cfg), SemiFinished: NewSemiFinishedClient(cfg), StocktakeItem: NewStocktakeItemClient(cfg), StocktakeOrder: NewStocktakeOrderClient(cfg), @@ -228,7 +233,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) OrderMaterialLedger: NewOrderMaterialLedgerClient(cfg), OutboundDetail: NewOutboundDetailClient(cfg), OutboundOrder: NewOutboundOrderClient(cfg), - PackageBox: NewPackageBoxClient(cfg), + Permission: NewPermissionClient(cfg), + Role: NewRoleClient(cfg), SemiFinished: NewSemiFinishedClient(cfg), StocktakeItem: NewStocktakeItemClient(cfg), StocktakeOrder: NewStocktakeOrderClient(cfg), @@ -265,7 +271,7 @@ func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ c.InboundDetail, c.InboundOrder, c.InspectionRecord, c.Inventory, c.InventoryLock, c.Material, c.OrderMaterialLedger, c.OutboundDetail, - c.OutboundOrder, c.PackageBox, c.SemiFinished, c.StocktakeItem, + c.OutboundOrder, c.Permission, c.Role, c.SemiFinished, c.StocktakeItem, c.StocktakeOrder, c.User, c.Zone, } { n.Use(hooks...) @@ -278,7 +284,7 @@ func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.InboundDetail, c.InboundOrder, c.InspectionRecord, c.Inventory, c.InventoryLock, c.Material, c.OrderMaterialLedger, c.OutboundDetail, - c.OutboundOrder, c.PackageBox, c.SemiFinished, c.StocktakeItem, + c.OutboundOrder, c.Permission, c.Role, c.SemiFinished, c.StocktakeItem, c.StocktakeOrder, c.User, c.Zone, } { n.Intercept(interceptors...) @@ -306,8 +312,10 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.OutboundDetail.mutate(ctx, m) case *OutboundOrderMutation: return c.OutboundOrder.mutate(ctx, m) - case *PackageBoxMutation: - return c.PackageBox.mutate(ctx, m) + case *PermissionMutation: + return c.Permission.mutate(ctx, m) + case *RoleMutation: + return c.Role.mutate(ctx, m) case *SemiFinishedMutation: return c.SemiFinished.mutate(ctx, m) case *StocktakeItemMutation: @@ -1520,107 +1528,107 @@ func (c *OutboundOrderClient) mutate(ctx context.Context, m *OutboundOrderMutati } } -// PackageBoxClient is a client for the PackageBox schema. -type PackageBoxClient struct { +// PermissionClient is a client for the Permission schema. +type PermissionClient struct { config } -// NewPackageBoxClient returns a client for the PackageBox from the given config. -func NewPackageBoxClient(c config) *PackageBoxClient { - return &PackageBoxClient{config: c} +// NewPermissionClient returns a client for the Permission from the given config. +func NewPermissionClient(c config) *PermissionClient { + return &PermissionClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `packagebox.Hooks(f(g(h())))`. -func (c *PackageBoxClient) Use(hooks ...Hook) { - c.hooks.PackageBox = append(c.hooks.PackageBox, hooks...) +// A call to `Use(f, g, h)` equals to `permission.Hooks(f(g(h())))`. +func (c *PermissionClient) Use(hooks ...Hook) { + c.hooks.Permission = append(c.hooks.Permission, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `packagebox.Intercept(f(g(h())))`. -func (c *PackageBoxClient) Intercept(interceptors ...Interceptor) { - c.inters.PackageBox = append(c.inters.PackageBox, interceptors...) +// A call to `Intercept(f, g, h)` equals to `permission.Intercept(f(g(h())))`. +func (c *PermissionClient) Intercept(interceptors ...Interceptor) { + c.inters.Permission = append(c.inters.Permission, interceptors...) } -// Create returns a builder for creating a PackageBox entity. -func (c *PackageBoxClient) Create() *PackageBoxCreate { - mutation := newPackageBoxMutation(c.config, OpCreate) - return &PackageBoxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +// Create returns a builder for creating a Permission entity. +func (c *PermissionClient) Create() *PermissionCreate { + mutation := newPermissionMutation(c.config, OpCreate) + return &PermissionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// CreateBulk returns a builder for creating a bulk of PackageBox entities. -func (c *PackageBoxClient) CreateBulk(builders ...*PackageBoxCreate) *PackageBoxCreateBulk { - return &PackageBoxCreateBulk{config: c.config, builders: builders} +// CreateBulk returns a builder for creating a bulk of Permission entities. +func (c *PermissionClient) CreateBulk(builders ...*PermissionCreate) *PermissionCreateBulk { + return &PermissionCreateBulk{config: c.config, builders: builders} } // MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates // a builder and applies setFunc on it. -func (c *PackageBoxClient) MapCreateBulk(slice any, setFunc func(*PackageBoxCreate, int)) *PackageBoxCreateBulk { +func (c *PermissionClient) MapCreateBulk(slice any, setFunc func(*PermissionCreate, int)) *PermissionCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { - return &PackageBoxCreateBulk{err: fmt.Errorf("calling to PackageBoxClient.MapCreateBulk with wrong type %T, need slice", slice)} + return &PermissionCreateBulk{err: fmt.Errorf("calling to PermissionClient.MapCreateBulk with wrong type %T, need slice", slice)} } - builders := make([]*PackageBoxCreate, rv.Len()) + builders := make([]*PermissionCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } - return &PackageBoxCreateBulk{config: c.config, builders: builders} + return &PermissionCreateBulk{config: c.config, builders: builders} } -// Update returns an update builder for PackageBox. -func (c *PackageBoxClient) Update() *PackageBoxUpdate { - mutation := newPackageBoxMutation(c.config, OpUpdate) - return &PackageBoxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +// Update returns an update builder for Permission. +func (c *PermissionClient) Update() *PermissionUpdate { + mutation := newPermissionMutation(c.config, OpUpdate) + return &PermissionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. -func (c *PackageBoxClient) UpdateOne(_m *PackageBox) *PackageBoxUpdateOne { - mutation := newPackageBoxMutation(c.config, OpUpdateOne, withPackageBox(_m)) - return &PackageBoxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +func (c *PermissionClient) UpdateOne(_m *Permission) *PermissionUpdateOne { + mutation := newPermissionMutation(c.config, OpUpdateOne, withPermission(_m)) + return &PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. -func (c *PackageBoxClient) UpdateOneID(id int) *PackageBoxUpdateOne { - mutation := newPackageBoxMutation(c.config, OpUpdateOne, withPackageBoxID(id)) - return &PackageBoxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +func (c *PermissionClient) UpdateOneID(id int) *PermissionUpdateOne { + mutation := newPermissionMutation(c.config, OpUpdateOne, withPermissionID(id)) + return &PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } -// Delete returns a delete builder for PackageBox. -func (c *PackageBoxClient) Delete() *PackageBoxDelete { - mutation := newPackageBoxMutation(c.config, OpDelete) - return &PackageBoxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +// Delete returns a delete builder for Permission. +func (c *PermissionClient) Delete() *PermissionDelete { + mutation := newPermissionMutation(c.config, OpDelete) + return &PermissionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. -func (c *PackageBoxClient) DeleteOne(_m *PackageBox) *PackageBoxDeleteOne { +func (c *PermissionClient) DeleteOne(_m *Permission) *PermissionDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *PackageBoxClient) DeleteOneID(id int) *PackageBoxDeleteOne { - builder := c.Delete().Where(packagebox.ID(id)) +func (c *PermissionClient) DeleteOneID(id int) *PermissionDeleteOne { + builder := c.Delete().Where(permission.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne - return &PackageBoxDeleteOne{builder} + return &PermissionDeleteOne{builder} } -// Query returns a query builder for PackageBox. -func (c *PackageBoxClient) Query() *PackageBoxQuery { - return &PackageBoxQuery{ +// Query returns a query builder for Permission. +func (c *PermissionClient) Query() *PermissionQuery { + return &PermissionQuery{ config: c.config, - ctx: &QueryContext{Type: TypePackageBox}, + ctx: &QueryContext{Type: TypePermission}, inters: c.Interceptors(), } } -// Get returns a PackageBox entity by its id. -func (c *PackageBoxClient) Get(ctx context.Context, id int) (*PackageBox, error) { - return c.Query().Where(packagebox.ID(id)).Only(ctx) +// Get returns a Permission entity by its id. +func (c *PermissionClient) Get(ctx context.Context, id int) (*Permission, error) { + return c.Query().Where(permission.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (c *PackageBoxClient) GetX(ctx context.Context, id int) *PackageBox { +func (c *PermissionClient) GetX(ctx context.Context, id int) *Permission { obj, err := c.Get(ctx, id) if err != nil { panic(err) @@ -1629,27 +1637,160 @@ func (c *PackageBoxClient) GetX(ctx context.Context, id int) *PackageBox { } // Hooks returns the client hooks. -func (c *PackageBoxClient) Hooks() []Hook { - return c.hooks.PackageBox +func (c *PermissionClient) Hooks() []Hook { + return c.hooks.Permission } // Interceptors returns the client interceptors. -func (c *PackageBoxClient) Interceptors() []Interceptor { - return c.inters.PackageBox +func (c *PermissionClient) Interceptors() []Interceptor { + return c.inters.Permission } -func (c *PackageBoxClient) mutate(ctx context.Context, m *PackageBoxMutation) (Value, error) { +func (c *PermissionClient) mutate(ctx context.Context, m *PermissionMutation) (Value, error) { switch m.Op() { case OpCreate: - return (&PackageBoxCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + return (&PermissionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: - return (&PackageBoxUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + return (&PermissionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: - return (&PackageBoxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + return (&PermissionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: - return (&PackageBoxDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + return (&PermissionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: - return nil, fmt.Errorf("ent: unknown PackageBox mutation op: %q", m.Op()) + return nil, fmt.Errorf("ent: unknown Permission mutation op: %q", m.Op()) + } +} + +// RoleClient is a client for the Role schema. +type RoleClient struct { + config +} + +// NewRoleClient returns a client for the Role from the given config. +func NewRoleClient(c config) *RoleClient { + return &RoleClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `role.Hooks(f(g(h())))`. +func (c *RoleClient) Use(hooks ...Hook) { + c.hooks.Role = append(c.hooks.Role, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `role.Intercept(f(g(h())))`. +func (c *RoleClient) Intercept(interceptors ...Interceptor) { + c.inters.Role = append(c.inters.Role, interceptors...) +} + +// Create returns a builder for creating a Role entity. +func (c *RoleClient) Create() *RoleCreate { + mutation := newRoleMutation(c.config, OpCreate) + return &RoleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Role entities. +func (c *RoleClient) CreateBulk(builders ...*RoleCreate) *RoleCreateBulk { + return &RoleCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *RoleClient) MapCreateBulk(slice any, setFunc func(*RoleCreate, int)) *RoleCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &RoleCreateBulk{err: fmt.Errorf("calling to RoleClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*RoleCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &RoleCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Role. +func (c *RoleClient) Update() *RoleUpdate { + mutation := newRoleMutation(c.config, OpUpdate) + return &RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *RoleClient) UpdateOne(_m *Role) *RoleUpdateOne { + mutation := newRoleMutation(c.config, OpUpdateOne, withRole(_m)) + return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *RoleClient) UpdateOneID(id int) *RoleUpdateOne { + mutation := newRoleMutation(c.config, OpUpdateOne, withRoleID(id)) + return &RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Role. +func (c *RoleClient) Delete() *RoleDelete { + mutation := newRoleMutation(c.config, OpDelete) + return &RoleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *RoleClient) DeleteOne(_m *Role) *RoleDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *RoleClient) DeleteOneID(id int) *RoleDeleteOne { + builder := c.Delete().Where(role.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &RoleDeleteOne{builder} +} + +// Query returns a query builder for Role. +func (c *RoleClient) Query() *RoleQuery { + return &RoleQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeRole}, + inters: c.Interceptors(), + } +} + +// Get returns a Role entity by its id. +func (c *RoleClient) Get(ctx context.Context, id int) (*Role, error) { + return c.Query().Where(role.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *RoleClient) GetX(ctx context.Context, id int) *Role { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *RoleClient) Hooks() []Hook { + return c.hooks.Role +} + +// Interceptors returns the client interceptors. +func (c *RoleClient) Interceptors() []Interceptor { + return c.inters.Role +} + +func (c *RoleClient) mutate(ctx context.Context, m *RoleMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RoleCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RoleDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Role mutation op: %q", m.Op()) } } @@ -2322,12 +2463,12 @@ func (c *ZoneClient) mutate(ctx context.Context, m *ZoneMutation) (Value, error) type ( hooks struct { InboundDetail, InboundOrder, InspectionRecord, Inventory, InventoryLock, - Material, OrderMaterialLedger, OutboundDetail, OutboundOrder, PackageBox, + Material, OrderMaterialLedger, OutboundDetail, OutboundOrder, Permission, Role, SemiFinished, StocktakeItem, StocktakeOrder, User, Zone []ent.Hook } inters struct { InboundDetail, InboundOrder, InspectionRecord, Inventory, InventoryLock, - Material, OrderMaterialLedger, OutboundDetail, OutboundOrder, PackageBox, + Material, OrderMaterialLedger, OutboundDetail, OutboundOrder, Permission, Role, SemiFinished, StocktakeItem, StocktakeOrder, User, Zone []ent.Interceptor } ) diff --git a/bj_power_wms/ent/ent.go b/bj_power_wms/ent/ent.go index b4eadeb..612435c 100644 --- a/bj_power_wms/ent/ent.go +++ b/bj_power_wms/ent/ent.go @@ -12,7 +12,8 @@ import ( "bj_power_wms/ent/ordermaterialledger" "bj_power_wms/ent/outbounddetail" "bj_power_wms/ent/outboundorder" - "bj_power_wms/ent/packagebox" + "bj_power_wms/ent/permission" + "bj_power_wms/ent/role" "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" @@ -96,7 +97,8 @@ func checkColumn(t, c string) error { ordermaterialledger.Table: ordermaterialledger.ValidColumn, outbounddetail.Table: outbounddetail.ValidColumn, outboundorder.Table: outboundorder.ValidColumn, - packagebox.Table: packagebox.ValidColumn, + permission.Table: permission.ValidColumn, + role.Table: role.ValidColumn, semifinished.Table: semifinished.ValidColumn, stocktakeitem.Table: stocktakeitem.ValidColumn, stocktakeorder.Table: stocktakeorder.ValidColumn, diff --git a/bj_power_wms/ent/hook/hook.go b/bj_power_wms/ent/hook/hook.go index 46c3626..79f8f12 100644 --- a/bj_power_wms/ent/hook/hook.go +++ b/bj_power_wms/ent/hook/hook.go @@ -116,16 +116,28 @@ func (f OutboundOrderFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Valu return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.OutboundOrderMutation", m) } -// The PackageBoxFunc type is an adapter to allow the use of ordinary -// function as PackageBox mutator. -type PackageBoxFunc func(context.Context, *ent.PackageBoxMutation) (ent.Value, error) +// The PermissionFunc type is an adapter to allow the use of ordinary +// function as Permission mutator. +type PermissionFunc func(context.Context, *ent.PermissionMutation) (ent.Value, error) // Mutate calls f(ctx, m). -func (f PackageBoxFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.PackageBoxMutation); ok { +func (f PermissionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.PermissionMutation); ok { return f(ctx, mv) } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PackageBoxMutation", m) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PermissionMutation", m) +} + +// The RoleFunc type is an adapter to allow the use of ordinary +// function as Role mutator. +type RoleFunc func(context.Context, *ent.RoleMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f RoleFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.RoleMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.RoleMutation", m) } // The SemiFinishedFunc type is an adapter to allow the use of ordinary diff --git a/bj_power_wms/ent/inboundorder.go b/bj_power_wms/ent/inboundorder.go index 6089749..8318e12 100644 --- a/bj_power_wms/ent/inboundorder.go +++ b/bj_power_wms/ent/inboundorder.go @@ -24,19 +24,19 @@ type InboundOrder struct { MaterialCode string `json:"materialCode,omitempty"` // 物料名称(冗余) MaterialName string `json:"materialName,omitempty"` - // ManageMode holds the value of the "manage_mode" field. + // 管理粒度 1批次/2序列号 ManageMode int `json:"manageMode,omitempty"` // 批次号(结构件) BatchNo string `json:"batchNo,omitempty"` // 入库区域 ZoneCode string `json:"zoneCode,omitempty"` - // 数量 + // 本次入库总数量(批次合计或SN条数) Quantity int `json:"quantity,omitempty"` // 操作人 Operator string `json:"operator,omitempty"` // 备注 Remark string `json:"remark,omitempty"` - // CreatedAt holds the value of the "created_at" field. + // 创建时间 CreatedAt int64 `json:"createdAt,omitempty"` selectValues sql.SelectValues } diff --git a/bj_power_wms/ent/inspectionrecord.go b/bj_power_wms/ent/inspectionrecord.go index eb7a9ab..4d07a1b 100644 --- a/bj_power_wms/ent/inspectionrecord.go +++ b/bj_power_wms/ent/inspectionrecord.go @@ -28,6 +28,14 @@ type InspectionRecord struct { Status string `json:"status,omitempty"` // 实测值(部分检验项) ResultValue string `json:"resultValue,omitempty"` + // 检验数量(抽检件数) + InspectQty int `json:"inspectQty,omitempty"` + // 合格数量(≤检验数量) + PassQty int `json:"passQty,omitempty"` + // 检测说明(检验项目/方法) + CheckDesc string `json:"checkDesc,omitempty"` + // 不合格原因(不合格时必填) + FailReason string `json:"failReason,omitempty"` // 检验人 Inspector string `json:"inspector,omitempty"` // 备注 @@ -44,9 +52,9 @@ func (*InspectionRecord) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case inspectionrecord.FieldID, inspectionrecord.FieldCreatedAt, inspectionrecord.FieldUpdatedAt: + case inspectionrecord.FieldID, inspectionrecord.FieldInspectQty, inspectionrecord.FieldPassQty, inspectionrecord.FieldCreatedAt, inspectionrecord.FieldUpdatedAt: values[i] = new(sql.NullInt64) - case inspectionrecord.FieldTargetType, inspectionrecord.FieldTargetID, inspectionrecord.FieldMaterialCode, inspectionrecord.FieldInspectionType, inspectionrecord.FieldStatus, inspectionrecord.FieldResultValue, inspectionrecord.FieldInspector, inspectionrecord.FieldRemark: + case inspectionrecord.FieldTargetType, inspectionrecord.FieldTargetID, inspectionrecord.FieldMaterialCode, inspectionrecord.FieldInspectionType, inspectionrecord.FieldStatus, inspectionrecord.FieldResultValue, inspectionrecord.FieldCheckDesc, inspectionrecord.FieldFailReason, inspectionrecord.FieldInspector, inspectionrecord.FieldRemark: values[i] = new(sql.NullString) default: values[i] = new(sql.UnknownType) @@ -105,6 +113,30 @@ func (_m *InspectionRecord) assignValues(columns []string, values []any) error { } else if value.Valid { _m.ResultValue = value.String } + case inspectionrecord.FieldInspectQty: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field inspect_qty", values[i]) + } else if value.Valid { + _m.InspectQty = int(value.Int64) + } + case inspectionrecord.FieldPassQty: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field pass_qty", values[i]) + } else if value.Valid { + _m.PassQty = int(value.Int64) + } + case inspectionrecord.FieldCheckDesc: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field check_desc", values[i]) + } else if value.Valid { + _m.CheckDesc = value.String + } + case inspectionrecord.FieldFailReason: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field fail_reason", values[i]) + } else if value.Valid { + _m.FailReason = value.String + } case inspectionrecord.FieldInspector: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field inspector", values[i]) @@ -183,6 +215,18 @@ func (_m *InspectionRecord) String() string { builder.WriteString("result_value=") builder.WriteString(_m.ResultValue) builder.WriteString(", ") + builder.WriteString("inspect_qty=") + builder.WriteString(fmt.Sprintf("%v", _m.InspectQty)) + builder.WriteString(", ") + builder.WriteString("pass_qty=") + builder.WriteString(fmt.Sprintf("%v", _m.PassQty)) + builder.WriteString(", ") + builder.WriteString("check_desc=") + builder.WriteString(_m.CheckDesc) + builder.WriteString(", ") + builder.WriteString("fail_reason=") + builder.WriteString(_m.FailReason) + builder.WriteString(", ") builder.WriteString("inspector=") builder.WriteString(_m.Inspector) builder.WriteString(", ") diff --git a/bj_power_wms/ent/inspectionrecord/inspectionrecord.go b/bj_power_wms/ent/inspectionrecord/inspectionrecord.go index aad65b5..ac33521 100644 --- a/bj_power_wms/ent/inspectionrecord/inspectionrecord.go +++ b/bj_power_wms/ent/inspectionrecord/inspectionrecord.go @@ -23,6 +23,14 @@ const ( FieldStatus = "status" // FieldResultValue holds the string denoting the result_value field in the database. FieldResultValue = "result_value" + // FieldInspectQty holds the string denoting the inspect_qty field in the database. + FieldInspectQty = "inspect_qty" + // FieldPassQty holds the string denoting the pass_qty field in the database. + FieldPassQty = "pass_qty" + // FieldCheckDesc holds the string denoting the check_desc field in the database. + FieldCheckDesc = "check_desc" + // FieldFailReason holds the string denoting the fail_reason field in the database. + FieldFailReason = "fail_reason" // FieldInspector holds the string denoting the inspector field in the database. FieldInspector = "inspector" // FieldRemark holds the string denoting the remark field in the database. @@ -44,6 +52,10 @@ var Columns = []string{ FieldInspectionType, FieldStatus, FieldResultValue, + FieldInspectQty, + FieldPassQty, + FieldCheckDesc, + FieldFailReason, FieldInspector, FieldRemark, FieldCreatedAt, @@ -65,6 +77,10 @@ var ( DefaultInspectionType string // DefaultStatus holds the default value on creation for the "status" field. DefaultStatus string + // DefaultInspectQty holds the default value on creation for the "inspect_qty" field. + DefaultInspectQty int + // DefaultPassQty holds the default value on creation for the "pass_qty" field. + DefaultPassQty int // DefaultCreatedAt holds the default value on creation for the "created_at" field. DefaultCreatedAt func() int64 // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. @@ -109,6 +125,26 @@ func ByResultValue(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldResultValue, opts...).ToFunc() } +// ByInspectQty orders the results by the inspect_qty field. +func ByInspectQty(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldInspectQty, opts...).ToFunc() +} + +// ByPassQty orders the results by the pass_qty field. +func ByPassQty(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPassQty, opts...).ToFunc() +} + +// ByCheckDesc orders the results by the check_desc field. +func ByCheckDesc(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCheckDesc, opts...).ToFunc() +} + +// ByFailReason orders the results by the fail_reason field. +func ByFailReason(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFailReason, opts...).ToFunc() +} + // ByInspector orders the results by the inspector field. func ByInspector(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldInspector, opts...).ToFunc() diff --git a/bj_power_wms/ent/inspectionrecord/where.go b/bj_power_wms/ent/inspectionrecord/where.go index 4eeba1b..f5aeeb3 100644 --- a/bj_power_wms/ent/inspectionrecord/where.go +++ b/bj_power_wms/ent/inspectionrecord/where.go @@ -83,6 +83,26 @@ func ResultValue(v string) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldEQ(FieldResultValue, v)) } +// InspectQty applies equality check predicate on the "inspect_qty" field. It's identical to InspectQtyEQ. +func InspectQty(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldInspectQty, v)) +} + +// PassQty applies equality check predicate on the "pass_qty" field. It's identical to PassQtyEQ. +func PassQty(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldPassQty, v)) +} + +// CheckDesc applies equality check predicate on the "check_desc" field. It's identical to CheckDescEQ. +func CheckDesc(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldCheckDesc, v)) +} + +// FailReason applies equality check predicate on the "fail_reason" field. It's identical to FailReasonEQ. +func FailReason(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldFailReason, v)) +} + // Inspector applies equality check predicate on the "inspector" field. It's identical to InspectorEQ. func Inspector(v string) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldEQ(FieldInspector, v)) @@ -503,6 +523,236 @@ func ResultValueContainsFold(v string) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldContainsFold(FieldResultValue, v)) } +// InspectQtyEQ applies the EQ predicate on the "inspect_qty" field. +func InspectQtyEQ(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldInspectQty, v)) +} + +// InspectQtyNEQ applies the NEQ predicate on the "inspect_qty" field. +func InspectQtyNEQ(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldInspectQty, v)) +} + +// InspectQtyIn applies the In predicate on the "inspect_qty" field. +func InspectQtyIn(vs ...int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldInspectQty, vs...)) +} + +// InspectQtyNotIn applies the NotIn predicate on the "inspect_qty" field. +func InspectQtyNotIn(vs ...int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldInspectQty, vs...)) +} + +// InspectQtyGT applies the GT predicate on the "inspect_qty" field. +func InspectQtyGT(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldInspectQty, v)) +} + +// InspectQtyGTE applies the GTE predicate on the "inspect_qty" field. +func InspectQtyGTE(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldInspectQty, v)) +} + +// InspectQtyLT applies the LT predicate on the "inspect_qty" field. +func InspectQtyLT(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldInspectQty, v)) +} + +// InspectQtyLTE applies the LTE predicate on the "inspect_qty" field. +func InspectQtyLTE(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldInspectQty, v)) +} + +// PassQtyEQ applies the EQ predicate on the "pass_qty" field. +func PassQtyEQ(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldPassQty, v)) +} + +// PassQtyNEQ applies the NEQ predicate on the "pass_qty" field. +func PassQtyNEQ(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldPassQty, v)) +} + +// PassQtyIn applies the In predicate on the "pass_qty" field. +func PassQtyIn(vs ...int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldPassQty, vs...)) +} + +// PassQtyNotIn applies the NotIn predicate on the "pass_qty" field. +func PassQtyNotIn(vs ...int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldPassQty, vs...)) +} + +// PassQtyGT applies the GT predicate on the "pass_qty" field. +func PassQtyGT(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldPassQty, v)) +} + +// PassQtyGTE applies the GTE predicate on the "pass_qty" field. +func PassQtyGTE(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldPassQty, v)) +} + +// PassQtyLT applies the LT predicate on the "pass_qty" field. +func PassQtyLT(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldPassQty, v)) +} + +// PassQtyLTE applies the LTE predicate on the "pass_qty" field. +func PassQtyLTE(v int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldPassQty, v)) +} + +// CheckDescEQ applies the EQ predicate on the "check_desc" field. +func CheckDescEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldCheckDesc, v)) +} + +// CheckDescNEQ applies the NEQ predicate on the "check_desc" field. +func CheckDescNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldCheckDesc, v)) +} + +// CheckDescIn applies the In predicate on the "check_desc" field. +func CheckDescIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldCheckDesc, vs...)) +} + +// CheckDescNotIn applies the NotIn predicate on the "check_desc" field. +func CheckDescNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldCheckDesc, vs...)) +} + +// CheckDescGT applies the GT predicate on the "check_desc" field. +func CheckDescGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldCheckDesc, v)) +} + +// CheckDescGTE applies the GTE predicate on the "check_desc" field. +func CheckDescGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldCheckDesc, v)) +} + +// CheckDescLT applies the LT predicate on the "check_desc" field. +func CheckDescLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldCheckDesc, v)) +} + +// CheckDescLTE applies the LTE predicate on the "check_desc" field. +func CheckDescLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldCheckDesc, v)) +} + +// CheckDescContains applies the Contains predicate on the "check_desc" field. +func CheckDescContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldCheckDesc, v)) +} + +// CheckDescHasPrefix applies the HasPrefix predicate on the "check_desc" field. +func CheckDescHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldCheckDesc, v)) +} + +// CheckDescHasSuffix applies the HasSuffix predicate on the "check_desc" field. +func CheckDescHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldCheckDesc, v)) +} + +// CheckDescIsNil applies the IsNil predicate on the "check_desc" field. +func CheckDescIsNil() predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIsNull(FieldCheckDesc)) +} + +// CheckDescNotNil applies the NotNil predicate on the "check_desc" field. +func CheckDescNotNil() predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotNull(FieldCheckDesc)) +} + +// CheckDescEqualFold applies the EqualFold predicate on the "check_desc" field. +func CheckDescEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldCheckDesc, v)) +} + +// CheckDescContainsFold applies the ContainsFold predicate on the "check_desc" field. +func CheckDescContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldCheckDesc, v)) +} + +// FailReasonEQ applies the EQ predicate on the "fail_reason" field. +func FailReasonEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldFailReason, v)) +} + +// FailReasonNEQ applies the NEQ predicate on the "fail_reason" field. +func FailReasonNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldFailReason, v)) +} + +// FailReasonIn applies the In predicate on the "fail_reason" field. +func FailReasonIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldFailReason, vs...)) +} + +// FailReasonNotIn applies the NotIn predicate on the "fail_reason" field. +func FailReasonNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldFailReason, vs...)) +} + +// FailReasonGT applies the GT predicate on the "fail_reason" field. +func FailReasonGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldFailReason, v)) +} + +// FailReasonGTE applies the GTE predicate on the "fail_reason" field. +func FailReasonGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldFailReason, v)) +} + +// FailReasonLT applies the LT predicate on the "fail_reason" field. +func FailReasonLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldFailReason, v)) +} + +// FailReasonLTE applies the LTE predicate on the "fail_reason" field. +func FailReasonLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldFailReason, v)) +} + +// FailReasonContains applies the Contains predicate on the "fail_reason" field. +func FailReasonContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldFailReason, v)) +} + +// FailReasonHasPrefix applies the HasPrefix predicate on the "fail_reason" field. +func FailReasonHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldFailReason, v)) +} + +// FailReasonHasSuffix applies the HasSuffix predicate on the "fail_reason" field. +func FailReasonHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldFailReason, v)) +} + +// FailReasonIsNil applies the IsNil predicate on the "fail_reason" field. +func FailReasonIsNil() predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIsNull(FieldFailReason)) +} + +// FailReasonNotNil applies the NotNil predicate on the "fail_reason" field. +func FailReasonNotNil() predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotNull(FieldFailReason)) +} + +// FailReasonEqualFold applies the EqualFold predicate on the "fail_reason" field. +func FailReasonEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldFailReason, v)) +} + +// FailReasonContainsFold applies the ContainsFold predicate on the "fail_reason" field. +func FailReasonContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldFailReason, v)) +} + // InspectorEQ applies the EQ predicate on the "inspector" field. func InspectorEQ(v string) predicate.InspectionRecord { return predicate.InspectionRecord(sql.FieldEQ(FieldInspector, v)) diff --git a/bj_power_wms/ent/inspectionrecord_create.go b/bj_power_wms/ent/inspectionrecord_create.go index b7cf66d..f9827db 100644 --- a/bj_power_wms/ent/inspectionrecord_create.go +++ b/bj_power_wms/ent/inspectionrecord_create.go @@ -81,6 +81,62 @@ func (_c *InspectionRecordCreate) SetNillableResultValue(v *string) *InspectionR return _c } +// SetInspectQty sets the "inspect_qty" field. +func (_c *InspectionRecordCreate) SetInspectQty(v int) *InspectionRecordCreate { + _c.mutation.SetInspectQty(v) + return _c +} + +// SetNillableInspectQty sets the "inspect_qty" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableInspectQty(v *int) *InspectionRecordCreate { + if v != nil { + _c.SetInspectQty(*v) + } + return _c +} + +// SetPassQty sets the "pass_qty" field. +func (_c *InspectionRecordCreate) SetPassQty(v int) *InspectionRecordCreate { + _c.mutation.SetPassQty(v) + return _c +} + +// SetNillablePassQty sets the "pass_qty" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillablePassQty(v *int) *InspectionRecordCreate { + if v != nil { + _c.SetPassQty(*v) + } + return _c +} + +// SetCheckDesc sets the "check_desc" field. +func (_c *InspectionRecordCreate) SetCheckDesc(v string) *InspectionRecordCreate { + _c.mutation.SetCheckDesc(v) + return _c +} + +// SetNillableCheckDesc sets the "check_desc" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableCheckDesc(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetCheckDesc(*v) + } + return _c +} + +// SetFailReason sets the "fail_reason" field. +func (_c *InspectionRecordCreate) SetFailReason(v string) *InspectionRecordCreate { + _c.mutation.SetFailReason(v) + return _c +} + +// SetNillableFailReason sets the "fail_reason" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableFailReason(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetFailReason(*v) + } + return _c +} + // SetInspector sets the "inspector" field. func (_c *InspectionRecordCreate) SetInspector(v string) *InspectionRecordCreate { _c.mutation.SetInspector(v) @@ -180,6 +236,14 @@ func (_c *InspectionRecordCreate) defaults() { v := inspectionrecord.DefaultStatus _c.mutation.SetStatus(v) } + if _, ok := _c.mutation.InspectQty(); !ok { + v := inspectionrecord.DefaultInspectQty + _c.mutation.SetInspectQty(v) + } + if _, ok := _c.mutation.PassQty(); !ok { + v := inspectionrecord.DefaultPassQty + _c.mutation.SetPassQty(v) + } if _, ok := _c.mutation.CreatedAt(); !ok { v := inspectionrecord.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) @@ -207,6 +271,12 @@ func (_c *InspectionRecordCreate) check() error { if _, ok := _c.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "InspectionRecord.status"`)} } + if _, ok := _c.mutation.InspectQty(); !ok { + return &ValidationError{Name: "inspect_qty", err: errors.New(`ent: missing required field "InspectionRecord.inspect_qty"`)} + } + if _, ok := _c.mutation.PassQty(); !ok { + return &ValidationError{Name: "pass_qty", err: errors.New(`ent: missing required field "InspectionRecord.pass_qty"`)} + } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "InspectionRecord.created_at"`)} } @@ -264,6 +334,22 @@ func (_c *InspectionRecordCreate) createSpec() (*InspectionRecord, *sqlgraph.Cre _spec.SetField(inspectionrecord.FieldResultValue, field.TypeString, value) _node.ResultValue = value } + if value, ok := _c.mutation.InspectQty(); ok { + _spec.SetField(inspectionrecord.FieldInspectQty, field.TypeInt, value) + _node.InspectQty = value + } + if value, ok := _c.mutation.PassQty(); ok { + _spec.SetField(inspectionrecord.FieldPassQty, field.TypeInt, value) + _node.PassQty = value + } + if value, ok := _c.mutation.CheckDesc(); ok { + _spec.SetField(inspectionrecord.FieldCheckDesc, field.TypeString, value) + _node.CheckDesc = value + } + if value, ok := _c.mutation.FailReason(); ok { + _spec.SetField(inspectionrecord.FieldFailReason, field.TypeString, value) + _node.FailReason = value + } if value, ok := _c.mutation.Inspector(); ok { _spec.SetField(inspectionrecord.FieldInspector, field.TypeString, value) _node.Inspector = value @@ -410,6 +496,78 @@ func (u *InspectionRecordUpsert) ClearResultValue() *InspectionRecordUpsert { return u } +// SetInspectQty sets the "inspect_qty" field. +func (u *InspectionRecordUpsert) SetInspectQty(v int) *InspectionRecordUpsert { + u.Set(inspectionrecord.FieldInspectQty, v) + return u +} + +// UpdateInspectQty sets the "inspect_qty" field to the value that was provided on create. +func (u *InspectionRecordUpsert) UpdateInspectQty() *InspectionRecordUpsert { + u.SetExcluded(inspectionrecord.FieldInspectQty) + return u +} + +// AddInspectQty adds v to the "inspect_qty" field. +func (u *InspectionRecordUpsert) AddInspectQty(v int) *InspectionRecordUpsert { + u.Add(inspectionrecord.FieldInspectQty, v) + return u +} + +// SetPassQty sets the "pass_qty" field. +func (u *InspectionRecordUpsert) SetPassQty(v int) *InspectionRecordUpsert { + u.Set(inspectionrecord.FieldPassQty, v) + return u +} + +// UpdatePassQty sets the "pass_qty" field to the value that was provided on create. +func (u *InspectionRecordUpsert) UpdatePassQty() *InspectionRecordUpsert { + u.SetExcluded(inspectionrecord.FieldPassQty) + return u +} + +// AddPassQty adds v to the "pass_qty" field. +func (u *InspectionRecordUpsert) AddPassQty(v int) *InspectionRecordUpsert { + u.Add(inspectionrecord.FieldPassQty, v) + return u +} + +// SetCheckDesc sets the "check_desc" field. +func (u *InspectionRecordUpsert) SetCheckDesc(v string) *InspectionRecordUpsert { + u.Set(inspectionrecord.FieldCheckDesc, v) + return u +} + +// UpdateCheckDesc sets the "check_desc" field to the value that was provided on create. +func (u *InspectionRecordUpsert) UpdateCheckDesc() *InspectionRecordUpsert { + u.SetExcluded(inspectionrecord.FieldCheckDesc) + return u +} + +// ClearCheckDesc clears the value of the "check_desc" field. +func (u *InspectionRecordUpsert) ClearCheckDesc() *InspectionRecordUpsert { + u.SetNull(inspectionrecord.FieldCheckDesc) + return u +} + +// SetFailReason sets the "fail_reason" field. +func (u *InspectionRecordUpsert) SetFailReason(v string) *InspectionRecordUpsert { + u.Set(inspectionrecord.FieldFailReason, v) + return u +} + +// UpdateFailReason sets the "fail_reason" field to the value that was provided on create. +func (u *InspectionRecordUpsert) UpdateFailReason() *InspectionRecordUpsert { + u.SetExcluded(inspectionrecord.FieldFailReason) + return u +} + +// ClearFailReason clears the value of the "fail_reason" field. +func (u *InspectionRecordUpsert) ClearFailReason() *InspectionRecordUpsert { + u.SetNull(inspectionrecord.FieldFailReason) + return u +} + // SetInspector sets the "inspector" field. func (u *InspectionRecordUpsert) SetInspector(v string) *InspectionRecordUpsert { u.Set(inspectionrecord.FieldInspector, v) @@ -613,6 +771,90 @@ func (u *InspectionRecordUpsertOne) ClearResultValue() *InspectionRecordUpsertOn }) } +// SetInspectQty sets the "inspect_qty" field. +func (u *InspectionRecordUpsertOne) SetInspectQty(v int) *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetInspectQty(v) + }) +} + +// AddInspectQty adds v to the "inspect_qty" field. +func (u *InspectionRecordUpsertOne) AddInspectQty(v int) *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.AddInspectQty(v) + }) +} + +// UpdateInspectQty sets the "inspect_qty" field to the value that was provided on create. +func (u *InspectionRecordUpsertOne) UpdateInspectQty() *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdateInspectQty() + }) +} + +// SetPassQty sets the "pass_qty" field. +func (u *InspectionRecordUpsertOne) SetPassQty(v int) *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetPassQty(v) + }) +} + +// AddPassQty adds v to the "pass_qty" field. +func (u *InspectionRecordUpsertOne) AddPassQty(v int) *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.AddPassQty(v) + }) +} + +// UpdatePassQty sets the "pass_qty" field to the value that was provided on create. +func (u *InspectionRecordUpsertOne) UpdatePassQty() *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdatePassQty() + }) +} + +// SetCheckDesc sets the "check_desc" field. +func (u *InspectionRecordUpsertOne) SetCheckDesc(v string) *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetCheckDesc(v) + }) +} + +// UpdateCheckDesc sets the "check_desc" field to the value that was provided on create. +func (u *InspectionRecordUpsertOne) UpdateCheckDesc() *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdateCheckDesc() + }) +} + +// ClearCheckDesc clears the value of the "check_desc" field. +func (u *InspectionRecordUpsertOne) ClearCheckDesc() *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.ClearCheckDesc() + }) +} + +// SetFailReason sets the "fail_reason" field. +func (u *InspectionRecordUpsertOne) SetFailReason(v string) *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetFailReason(v) + }) +} + +// UpdateFailReason sets the "fail_reason" field to the value that was provided on create. +func (u *InspectionRecordUpsertOne) UpdateFailReason() *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdateFailReason() + }) +} + +// ClearFailReason clears the value of the "fail_reason" field. +func (u *InspectionRecordUpsertOne) ClearFailReason() *InspectionRecordUpsertOne { + return u.Update(func(s *InspectionRecordUpsert) { + s.ClearFailReason() + }) +} + // SetInspector sets the "inspector" field. func (u *InspectionRecordUpsertOne) SetInspector(v string) *InspectionRecordUpsertOne { return u.Update(func(s *InspectionRecordUpsert) { @@ -992,6 +1234,90 @@ func (u *InspectionRecordUpsertBulk) ClearResultValue() *InspectionRecordUpsertB }) } +// SetInspectQty sets the "inspect_qty" field. +func (u *InspectionRecordUpsertBulk) SetInspectQty(v int) *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetInspectQty(v) + }) +} + +// AddInspectQty adds v to the "inspect_qty" field. +func (u *InspectionRecordUpsertBulk) AddInspectQty(v int) *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.AddInspectQty(v) + }) +} + +// UpdateInspectQty sets the "inspect_qty" field to the value that was provided on create. +func (u *InspectionRecordUpsertBulk) UpdateInspectQty() *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdateInspectQty() + }) +} + +// SetPassQty sets the "pass_qty" field. +func (u *InspectionRecordUpsertBulk) SetPassQty(v int) *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetPassQty(v) + }) +} + +// AddPassQty adds v to the "pass_qty" field. +func (u *InspectionRecordUpsertBulk) AddPassQty(v int) *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.AddPassQty(v) + }) +} + +// UpdatePassQty sets the "pass_qty" field to the value that was provided on create. +func (u *InspectionRecordUpsertBulk) UpdatePassQty() *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdatePassQty() + }) +} + +// SetCheckDesc sets the "check_desc" field. +func (u *InspectionRecordUpsertBulk) SetCheckDesc(v string) *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetCheckDesc(v) + }) +} + +// UpdateCheckDesc sets the "check_desc" field to the value that was provided on create. +func (u *InspectionRecordUpsertBulk) UpdateCheckDesc() *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdateCheckDesc() + }) +} + +// ClearCheckDesc clears the value of the "check_desc" field. +func (u *InspectionRecordUpsertBulk) ClearCheckDesc() *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.ClearCheckDesc() + }) +} + +// SetFailReason sets the "fail_reason" field. +func (u *InspectionRecordUpsertBulk) SetFailReason(v string) *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.SetFailReason(v) + }) +} + +// UpdateFailReason sets the "fail_reason" field to the value that was provided on create. +func (u *InspectionRecordUpsertBulk) UpdateFailReason() *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.UpdateFailReason() + }) +} + +// ClearFailReason clears the value of the "fail_reason" field. +func (u *InspectionRecordUpsertBulk) ClearFailReason() *InspectionRecordUpsertBulk { + return u.Update(func(s *InspectionRecordUpsert) { + s.ClearFailReason() + }) +} + // SetInspector sets the "inspector" field. func (u *InspectionRecordUpsertBulk) SetInspector(v string) *InspectionRecordUpsertBulk { return u.Update(func(s *InspectionRecordUpsert) { diff --git a/bj_power_wms/ent/inspectionrecord_update.go b/bj_power_wms/ent/inspectionrecord_update.go index 07025b7..6a7d5d6 100644 --- a/bj_power_wms/ent/inspectionrecord_update.go +++ b/bj_power_wms/ent/inspectionrecord_update.go @@ -117,6 +117,88 @@ func (_u *InspectionRecordUpdate) ClearResultValue() *InspectionRecordUpdate { return _u } +// SetInspectQty sets the "inspect_qty" field. +func (_u *InspectionRecordUpdate) SetInspectQty(v int) *InspectionRecordUpdate { + _u.mutation.ResetInspectQty() + _u.mutation.SetInspectQty(v) + return _u +} + +// SetNillableInspectQty sets the "inspect_qty" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableInspectQty(v *int) *InspectionRecordUpdate { + if v != nil { + _u.SetInspectQty(*v) + } + return _u +} + +// AddInspectQty adds value to the "inspect_qty" field. +func (_u *InspectionRecordUpdate) AddInspectQty(v int) *InspectionRecordUpdate { + _u.mutation.AddInspectQty(v) + return _u +} + +// SetPassQty sets the "pass_qty" field. +func (_u *InspectionRecordUpdate) SetPassQty(v int) *InspectionRecordUpdate { + _u.mutation.ResetPassQty() + _u.mutation.SetPassQty(v) + return _u +} + +// SetNillablePassQty sets the "pass_qty" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillablePassQty(v *int) *InspectionRecordUpdate { + if v != nil { + _u.SetPassQty(*v) + } + return _u +} + +// AddPassQty adds value to the "pass_qty" field. +func (_u *InspectionRecordUpdate) AddPassQty(v int) *InspectionRecordUpdate { + _u.mutation.AddPassQty(v) + return _u +} + +// SetCheckDesc sets the "check_desc" field. +func (_u *InspectionRecordUpdate) SetCheckDesc(v string) *InspectionRecordUpdate { + _u.mutation.SetCheckDesc(v) + return _u +} + +// SetNillableCheckDesc sets the "check_desc" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableCheckDesc(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetCheckDesc(*v) + } + return _u +} + +// ClearCheckDesc clears the value of the "check_desc" field. +func (_u *InspectionRecordUpdate) ClearCheckDesc() *InspectionRecordUpdate { + _u.mutation.ClearCheckDesc() + return _u +} + +// SetFailReason sets the "fail_reason" field. +func (_u *InspectionRecordUpdate) SetFailReason(v string) *InspectionRecordUpdate { + _u.mutation.SetFailReason(v) + return _u +} + +// SetNillableFailReason sets the "fail_reason" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableFailReason(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetFailReason(*v) + } + return _u +} + +// ClearFailReason clears the value of the "fail_reason" field. +func (_u *InspectionRecordUpdate) ClearFailReason() *InspectionRecordUpdate { + _u.mutation.ClearFailReason() + return _u +} + // SetInspector sets the "inspector" field. func (_u *InspectionRecordUpdate) SetInspector(v string) *InspectionRecordUpdate { _u.mutation.SetInspector(v) @@ -261,6 +343,30 @@ func (_u *InspectionRecordUpdate) sqlSave(ctx context.Context) (_node int, err e if _u.mutation.ResultValueCleared() { _spec.ClearField(inspectionrecord.FieldResultValue, field.TypeString) } + if value, ok := _u.mutation.InspectQty(); ok { + _spec.SetField(inspectionrecord.FieldInspectQty, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedInspectQty(); ok { + _spec.AddField(inspectionrecord.FieldInspectQty, field.TypeInt, value) + } + if value, ok := _u.mutation.PassQty(); ok { + _spec.SetField(inspectionrecord.FieldPassQty, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedPassQty(); ok { + _spec.AddField(inspectionrecord.FieldPassQty, field.TypeInt, value) + } + if value, ok := _u.mutation.CheckDesc(); ok { + _spec.SetField(inspectionrecord.FieldCheckDesc, field.TypeString, value) + } + if _u.mutation.CheckDescCleared() { + _spec.ClearField(inspectionrecord.FieldCheckDesc, field.TypeString) + } + if value, ok := _u.mutation.FailReason(); ok { + _spec.SetField(inspectionrecord.FieldFailReason, field.TypeString, value) + } + if _u.mutation.FailReasonCleared() { + _spec.ClearField(inspectionrecord.FieldFailReason, field.TypeString) + } if value, ok := _u.mutation.Inspector(); ok { _spec.SetField(inspectionrecord.FieldInspector, field.TypeString, value) } @@ -395,6 +501,88 @@ func (_u *InspectionRecordUpdateOne) ClearResultValue() *InspectionRecordUpdateO return _u } +// SetInspectQty sets the "inspect_qty" field. +func (_u *InspectionRecordUpdateOne) SetInspectQty(v int) *InspectionRecordUpdateOne { + _u.mutation.ResetInspectQty() + _u.mutation.SetInspectQty(v) + return _u +} + +// SetNillableInspectQty sets the "inspect_qty" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableInspectQty(v *int) *InspectionRecordUpdateOne { + if v != nil { + _u.SetInspectQty(*v) + } + return _u +} + +// AddInspectQty adds value to the "inspect_qty" field. +func (_u *InspectionRecordUpdateOne) AddInspectQty(v int) *InspectionRecordUpdateOne { + _u.mutation.AddInspectQty(v) + return _u +} + +// SetPassQty sets the "pass_qty" field. +func (_u *InspectionRecordUpdateOne) SetPassQty(v int) *InspectionRecordUpdateOne { + _u.mutation.ResetPassQty() + _u.mutation.SetPassQty(v) + return _u +} + +// SetNillablePassQty sets the "pass_qty" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillablePassQty(v *int) *InspectionRecordUpdateOne { + if v != nil { + _u.SetPassQty(*v) + } + return _u +} + +// AddPassQty adds value to the "pass_qty" field. +func (_u *InspectionRecordUpdateOne) AddPassQty(v int) *InspectionRecordUpdateOne { + _u.mutation.AddPassQty(v) + return _u +} + +// SetCheckDesc sets the "check_desc" field. +func (_u *InspectionRecordUpdateOne) SetCheckDesc(v string) *InspectionRecordUpdateOne { + _u.mutation.SetCheckDesc(v) + return _u +} + +// SetNillableCheckDesc sets the "check_desc" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableCheckDesc(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetCheckDesc(*v) + } + return _u +} + +// ClearCheckDesc clears the value of the "check_desc" field. +func (_u *InspectionRecordUpdateOne) ClearCheckDesc() *InspectionRecordUpdateOne { + _u.mutation.ClearCheckDesc() + return _u +} + +// SetFailReason sets the "fail_reason" field. +func (_u *InspectionRecordUpdateOne) SetFailReason(v string) *InspectionRecordUpdateOne { + _u.mutation.SetFailReason(v) + return _u +} + +// SetNillableFailReason sets the "fail_reason" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableFailReason(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetFailReason(*v) + } + return _u +} + +// ClearFailReason clears the value of the "fail_reason" field. +func (_u *InspectionRecordUpdateOne) ClearFailReason() *InspectionRecordUpdateOne { + _u.mutation.ClearFailReason() + return _u +} + // SetInspector sets the "inspector" field. func (_u *InspectionRecordUpdateOne) SetInspector(v string) *InspectionRecordUpdateOne { _u.mutation.SetInspector(v) @@ -569,6 +757,30 @@ func (_u *InspectionRecordUpdateOne) sqlSave(ctx context.Context) (_node *Inspec if _u.mutation.ResultValueCleared() { _spec.ClearField(inspectionrecord.FieldResultValue, field.TypeString) } + if value, ok := _u.mutation.InspectQty(); ok { + _spec.SetField(inspectionrecord.FieldInspectQty, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedInspectQty(); ok { + _spec.AddField(inspectionrecord.FieldInspectQty, field.TypeInt, value) + } + if value, ok := _u.mutation.PassQty(); ok { + _spec.SetField(inspectionrecord.FieldPassQty, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedPassQty(); ok { + _spec.AddField(inspectionrecord.FieldPassQty, field.TypeInt, value) + } + if value, ok := _u.mutation.CheckDesc(); ok { + _spec.SetField(inspectionrecord.FieldCheckDesc, field.TypeString, value) + } + if _u.mutation.CheckDescCleared() { + _spec.ClearField(inspectionrecord.FieldCheckDesc, field.TypeString) + } + if value, ok := _u.mutation.FailReason(); ok { + _spec.SetField(inspectionrecord.FieldFailReason, field.TypeString, value) + } + if _u.mutation.FailReasonCleared() { + _spec.ClearField(inspectionrecord.FieldFailReason, field.TypeString) + } if value, ok := _u.mutation.Inspector(); ok { _spec.SetField(inspectionrecord.FieldInspector, field.TypeString, value) } diff --git a/bj_power_wms/ent/migrate/schema.go b/bj_power_wms/ent/migrate/schema.go index 1ac1cf3..e8a2d5b 100644 --- a/bj_power_wms/ent/migrate/schema.go +++ b/bj_power_wms/ent/migrate/schema.go @@ -3,6 +3,7 @@ package migrate import ( + "entgo.io/ent/dialect/entsql" "entgo.io/ent/dialect/sql/schema" "entgo.io/ent/schema/field" ) @@ -83,6 +84,10 @@ var ( {Name: "inspection_type", Type: field.TypeString, Default: "incoming"}, {Name: "status", Type: field.TypeString, Default: "未检"}, {Name: "result_value", Type: field.TypeString, Nullable: true}, + {Name: "inspect_qty", Type: field.TypeInt, Default: 0}, + {Name: "pass_qty", Type: field.TypeInt, Default: 0}, + {Name: "check_desc", Type: field.TypeString, Nullable: true}, + {Name: "fail_reason", Type: field.TypeString, Nullable: true}, {Name: "inspector", Type: field.TypeString, Nullable: true}, {Name: "remark", Type: field.TypeString, Nullable: true}, {Name: "created_at", Type: field.TypeInt64}, @@ -326,6 +331,9 @@ var ( {Name: "reviewer", Type: field.TypeString, Nullable: true}, {Name: "target_dock", Type: field.TypeString, Nullable: true}, {Name: "remark", Type: field.TypeString, Nullable: true}, + {Name: "box_no", Type: field.TypeString, Nullable: true}, + {Name: "box_sn_list", Type: field.TypeString, Nullable: true}, + {Name: "contract_no", Type: field.TypeString, Nullable: true}, {Name: "created_at", Type: field.TypeInt64}, } // OutboundOrdersTable holds the schema information for the "outbound_orders" table. @@ -349,41 +357,59 @@ var ( Unique: false, Columns: []*schema.Column{OutboundOrdersColumns[2]}, }, + { + Name: "outboundorder_box_no", + Unique: false, + Columns: []*schema.Column{OutboundOrdersColumns[14]}, + }, }, } - // PackageBoxesColumns holds the columns for the "package_boxes" table. - PackageBoxesColumns = []*schema.Column{ + // PermissionsColumns holds the columns for the "permissions" table. + PermissionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "box_no", Type: field.TypeString, Unique: true}, - {Name: "sn_list", Type: field.TypeString, Nullable: true}, - {Name: "material_code", Type: field.TypeString, Nullable: true}, - {Name: "quantity", Type: field.TypeInt, Default: 0}, - {Name: "operator", Type: field.TypeString, Nullable: true}, - {Name: "contract_no", Type: field.TypeString, Nullable: true}, - {Name: "remark", Type: field.TypeString, Nullable: true}, + {Name: "code", Type: field.TypeString, Unique: true, Size: 64}, + {Name: "name", Type: field.TypeString, Size: 64}, + {Name: "type", Type: field.TypeString, Size: 20, Default: "MENU"}, + {Name: "path", Type: field.TypeString, Nullable: true, Size: 128, Default: ""}, + {Name: "icon", Type: field.TypeString, Nullable: true, Size: 64, Default: ""}, + {Name: "sort", Type: field.TypeInt, Nullable: true, Default: 0}, + {Name: "remark", Type: field.TypeString, Nullable: true, Size: 255, Default: ""}, {Name: "created_at", Type: field.TypeInt64}, - {Name: "updated_at", Type: field.TypeInt64, Nullable: true}, + {Name: "updated_at", Type: field.TypeInt64}, } - // PackageBoxesTable holds the schema information for the "package_boxes" table. - PackageBoxesTable = &schema.Table{ - Name: "package_boxes", - Columns: PackageBoxesColumns, - PrimaryKey: []*schema.Column{PackageBoxesColumns[0]}, + // PermissionsTable holds the schema information for the "permissions" table. + PermissionsTable = &schema.Table{ + Name: "permissions", + Columns: PermissionsColumns, + PrimaryKey: []*schema.Column{PermissionsColumns[0]}, Indexes: []*schema.Index{ { - Name: "packagebox_material_code", - Unique: false, - Columns: []*schema.Column{PackageBoxesColumns[3]}, + Name: "permission_code", + Unique: true, + Columns: []*schema.Column{PermissionsColumns[1]}, }, + }, + } + // RolesColumns holds the columns for the "roles" table. + RolesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "name", Type: field.TypeString, Size: 64}, + {Name: "code", Type: field.TypeString, Unique: true, Size: 64}, + {Name: "remark", Type: field.TypeString, Nullable: true, Size: 255, Default: ""}, + {Name: "permission_codes", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "created_at", Type: field.TypeInt64}, + {Name: "updated_at", Type: field.TypeInt64}, + } + // RolesTable holds the schema information for the "roles" table. + RolesTable = &schema.Table{ + Name: "roles", + Columns: RolesColumns, + PrimaryKey: []*schema.Column{RolesColumns[0]}, + Indexes: []*schema.Index{ { - Name: "packagebox_contract_no", - Unique: false, - Columns: []*schema.Column{PackageBoxesColumns[6]}, - }, - { - Name: "packagebox_operator", - Unique: false, - Columns: []*schema.Column{PackageBoxesColumns[5]}, + Name: "role_code", + Unique: true, + Columns: []*schema.Column{RolesColumns[2]}, }, }, } @@ -480,6 +506,7 @@ var ( {Name: "password", Type: field.TypeString}, {Name: "real_name", Type: field.TypeString, Nullable: true}, {Name: "role", Type: field.TypeString, Default: "operator"}, + {Name: "role_id", Type: field.TypeInt, Nullable: true}, {Name: "dept", Type: field.TypeString, Nullable: true}, {Name: "phone", Type: field.TypeString, Nullable: true}, {Name: "is_active", Type: field.TypeBool, Default: true}, @@ -527,7 +554,8 @@ var ( OrderMaterialLedgersTable, OutboundDetailsTable, OutboundOrdersTable, - PackageBoxesTable, + PermissionsTable, + RolesTable, SemiFinishedsTable, StocktakeItemsTable, StocktakeOrdersTable, @@ -537,4 +565,10 @@ var ( ) func init() { + PermissionsTable.Annotation = &entsql.Annotation{ + Table: "permissions", + } + RolesTable.Annotation = &entsql.Annotation{ + Table: "roles", + } } diff --git a/bj_power_wms/ent/mutation.go b/bj_power_wms/ent/mutation.go index 6b3d1ca..9cd11e6 100644 --- a/bj_power_wms/ent/mutation.go +++ b/bj_power_wms/ent/mutation.go @@ -12,8 +12,9 @@ import ( "bj_power_wms/ent/ordermaterialledger" "bj_power_wms/ent/outbounddetail" "bj_power_wms/ent/outboundorder" - "bj_power_wms/ent/packagebox" + "bj_power_wms/ent/permission" "bj_power_wms/ent/predicate" + "bj_power_wms/ent/role" "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" @@ -46,7 +47,8 @@ const ( TypeOrderMaterialLedger = "OrderMaterialLedger" TypeOutboundDetail = "OutboundDetail" TypeOutboundOrder = "OutboundOrder" - TypePackageBox = "PackageBox" + TypePermission = "Permission" + TypeRole = "Role" TypeSemiFinished = "SemiFinished" TypeStocktakeItem = "StocktakeItem" TypeStocktakeOrder = "StocktakeOrder" @@ -1838,6 +1840,12 @@ type InspectionRecordMutation struct { inspection_type *string status *string result_value *string + inspect_qty *int + addinspect_qty *int + pass_qty *int + addpass_qty *int + check_desc *string + fail_reason *string inspector *string remark *string created_at *int64 @@ -2177,6 +2185,216 @@ func (m *InspectionRecordMutation) ResetResultValue() { delete(m.clearedFields, inspectionrecord.FieldResultValue) } +// SetInspectQty sets the "inspect_qty" field. +func (m *InspectionRecordMutation) SetInspectQty(i int) { + m.inspect_qty = &i + m.addinspect_qty = nil +} + +// InspectQty returns the value of the "inspect_qty" field in the mutation. +func (m *InspectionRecordMutation) InspectQty() (r int, exists bool) { + v := m.inspect_qty + if v == nil { + return + } + return *v, true +} + +// OldInspectQty returns the old "inspect_qty" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldInspectQty(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldInspectQty is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldInspectQty requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldInspectQty: %w", err) + } + return oldValue.InspectQty, nil +} + +// AddInspectQty adds i to the "inspect_qty" field. +func (m *InspectionRecordMutation) AddInspectQty(i int) { + if m.addinspect_qty != nil { + *m.addinspect_qty += i + } else { + m.addinspect_qty = &i + } +} + +// AddedInspectQty returns the value that was added to the "inspect_qty" field in this mutation. +func (m *InspectionRecordMutation) AddedInspectQty() (r int, exists bool) { + v := m.addinspect_qty + if v == nil { + return + } + return *v, true +} + +// ResetInspectQty resets all changes to the "inspect_qty" field. +func (m *InspectionRecordMutation) ResetInspectQty() { + m.inspect_qty = nil + m.addinspect_qty = nil +} + +// SetPassQty sets the "pass_qty" field. +func (m *InspectionRecordMutation) SetPassQty(i int) { + m.pass_qty = &i + m.addpass_qty = nil +} + +// PassQty returns the value of the "pass_qty" field in the mutation. +func (m *InspectionRecordMutation) PassQty() (r int, exists bool) { + v := m.pass_qty + if v == nil { + return + } + return *v, true +} + +// OldPassQty returns the old "pass_qty" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldPassQty(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPassQty is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPassQty requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPassQty: %w", err) + } + return oldValue.PassQty, nil +} + +// AddPassQty adds i to the "pass_qty" field. +func (m *InspectionRecordMutation) AddPassQty(i int) { + if m.addpass_qty != nil { + *m.addpass_qty += i + } else { + m.addpass_qty = &i + } +} + +// AddedPassQty returns the value that was added to the "pass_qty" field in this mutation. +func (m *InspectionRecordMutation) AddedPassQty() (r int, exists bool) { + v := m.addpass_qty + if v == nil { + return + } + return *v, true +} + +// ResetPassQty resets all changes to the "pass_qty" field. +func (m *InspectionRecordMutation) ResetPassQty() { + m.pass_qty = nil + m.addpass_qty = nil +} + +// SetCheckDesc sets the "check_desc" field. +func (m *InspectionRecordMutation) SetCheckDesc(s string) { + m.check_desc = &s +} + +// CheckDesc returns the value of the "check_desc" field in the mutation. +func (m *InspectionRecordMutation) CheckDesc() (r string, exists bool) { + v := m.check_desc + if v == nil { + return + } + return *v, true +} + +// OldCheckDesc returns the old "check_desc" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldCheckDesc(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCheckDesc is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCheckDesc requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCheckDesc: %w", err) + } + return oldValue.CheckDesc, nil +} + +// ClearCheckDesc clears the value of the "check_desc" field. +func (m *InspectionRecordMutation) ClearCheckDesc() { + m.check_desc = nil + m.clearedFields[inspectionrecord.FieldCheckDesc] = struct{}{} +} + +// CheckDescCleared returns if the "check_desc" field was cleared in this mutation. +func (m *InspectionRecordMutation) CheckDescCleared() bool { + _, ok := m.clearedFields[inspectionrecord.FieldCheckDesc] + return ok +} + +// ResetCheckDesc resets all changes to the "check_desc" field. +func (m *InspectionRecordMutation) ResetCheckDesc() { + m.check_desc = nil + delete(m.clearedFields, inspectionrecord.FieldCheckDesc) +} + +// SetFailReason sets the "fail_reason" field. +func (m *InspectionRecordMutation) SetFailReason(s string) { + m.fail_reason = &s +} + +// FailReason returns the value of the "fail_reason" field in the mutation. +func (m *InspectionRecordMutation) FailReason() (r string, exists bool) { + v := m.fail_reason + if v == nil { + return + } + return *v, true +} + +// OldFailReason returns the old "fail_reason" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldFailReason(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFailReason is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFailReason requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFailReason: %w", err) + } + return oldValue.FailReason, nil +} + +// ClearFailReason clears the value of the "fail_reason" field. +func (m *InspectionRecordMutation) ClearFailReason() { + m.fail_reason = nil + m.clearedFields[inspectionrecord.FieldFailReason] = struct{}{} +} + +// FailReasonCleared returns if the "fail_reason" field was cleared in this mutation. +func (m *InspectionRecordMutation) FailReasonCleared() bool { + _, ok := m.clearedFields[inspectionrecord.FieldFailReason] + return ok +} + +// ResetFailReason resets all changes to the "fail_reason" field. +func (m *InspectionRecordMutation) ResetFailReason() { + m.fail_reason = nil + delete(m.clearedFields, inspectionrecord.FieldFailReason) +} + // SetInspector sets the "inspector" field. func (m *InspectionRecordMutation) SetInspector(s string) { m.inspector = &s @@ -2421,7 +2639,7 @@ func (m *InspectionRecordMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *InspectionRecordMutation) Fields() []string { - fields := make([]string, 0, 10) + fields := make([]string, 0, 14) if m.target_type != nil { fields = append(fields, inspectionrecord.FieldTargetType) } @@ -2440,6 +2658,18 @@ func (m *InspectionRecordMutation) Fields() []string { if m.result_value != nil { fields = append(fields, inspectionrecord.FieldResultValue) } + if m.inspect_qty != nil { + fields = append(fields, inspectionrecord.FieldInspectQty) + } + if m.pass_qty != nil { + fields = append(fields, inspectionrecord.FieldPassQty) + } + if m.check_desc != nil { + fields = append(fields, inspectionrecord.FieldCheckDesc) + } + if m.fail_reason != nil { + fields = append(fields, inspectionrecord.FieldFailReason) + } if m.inspector != nil { fields = append(fields, inspectionrecord.FieldInspector) } @@ -2472,6 +2702,14 @@ func (m *InspectionRecordMutation) Field(name string) (ent.Value, bool) { return m.Status() case inspectionrecord.FieldResultValue: return m.ResultValue() + case inspectionrecord.FieldInspectQty: + return m.InspectQty() + case inspectionrecord.FieldPassQty: + return m.PassQty() + case inspectionrecord.FieldCheckDesc: + return m.CheckDesc() + case inspectionrecord.FieldFailReason: + return m.FailReason() case inspectionrecord.FieldInspector: return m.Inspector() case inspectionrecord.FieldRemark: @@ -2501,6 +2739,14 @@ func (m *InspectionRecordMutation) OldField(ctx context.Context, name string) (e return m.OldStatus(ctx) case inspectionrecord.FieldResultValue: return m.OldResultValue(ctx) + case inspectionrecord.FieldInspectQty: + return m.OldInspectQty(ctx) + case inspectionrecord.FieldPassQty: + return m.OldPassQty(ctx) + case inspectionrecord.FieldCheckDesc: + return m.OldCheckDesc(ctx) + case inspectionrecord.FieldFailReason: + return m.OldFailReason(ctx) case inspectionrecord.FieldInspector: return m.OldInspector(ctx) case inspectionrecord.FieldRemark: @@ -2560,6 +2806,34 @@ func (m *InspectionRecordMutation) SetField(name string, value ent.Value) error } m.SetResultValue(v) return nil + case inspectionrecord.FieldInspectQty: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetInspectQty(v) + return nil + case inspectionrecord.FieldPassQty: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPassQty(v) + return nil + case inspectionrecord.FieldCheckDesc: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCheckDesc(v) + return nil + case inspectionrecord.FieldFailReason: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFailReason(v) + return nil case inspectionrecord.FieldInspector: v, ok := value.(string) if !ok { @@ -2596,6 +2870,12 @@ func (m *InspectionRecordMutation) SetField(name string, value ent.Value) error // this mutation. func (m *InspectionRecordMutation) AddedFields() []string { var fields []string + if m.addinspect_qty != nil { + fields = append(fields, inspectionrecord.FieldInspectQty) + } + if m.addpass_qty != nil { + fields = append(fields, inspectionrecord.FieldPassQty) + } if m.addcreated_at != nil { fields = append(fields, inspectionrecord.FieldCreatedAt) } @@ -2610,6 +2890,10 @@ func (m *InspectionRecordMutation) AddedFields() []string { // was not set, or was not defined in the schema. func (m *InspectionRecordMutation) AddedField(name string) (ent.Value, bool) { switch name { + case inspectionrecord.FieldInspectQty: + return m.AddedInspectQty() + case inspectionrecord.FieldPassQty: + return m.AddedPassQty() case inspectionrecord.FieldCreatedAt: return m.AddedCreatedAt() case inspectionrecord.FieldUpdatedAt: @@ -2623,6 +2907,20 @@ func (m *InspectionRecordMutation) AddedField(name string) (ent.Value, bool) { // type. func (m *InspectionRecordMutation) AddField(name string, value ent.Value) error { switch name { + case inspectionrecord.FieldInspectQty: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddInspectQty(v) + return nil + case inspectionrecord.FieldPassQty: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddPassQty(v) + return nil case inspectionrecord.FieldCreatedAt: v, ok := value.(int64) if !ok { @@ -2648,6 +2946,12 @@ func (m *InspectionRecordMutation) ClearedFields() []string { if m.FieldCleared(inspectionrecord.FieldResultValue) { fields = append(fields, inspectionrecord.FieldResultValue) } + if m.FieldCleared(inspectionrecord.FieldCheckDesc) { + fields = append(fields, inspectionrecord.FieldCheckDesc) + } + if m.FieldCleared(inspectionrecord.FieldFailReason) { + fields = append(fields, inspectionrecord.FieldFailReason) + } if m.FieldCleared(inspectionrecord.FieldInspector) { fields = append(fields, inspectionrecord.FieldInspector) } @@ -2671,6 +2975,12 @@ func (m *InspectionRecordMutation) ClearField(name string) error { case inspectionrecord.FieldResultValue: m.ClearResultValue() return nil + case inspectionrecord.FieldCheckDesc: + m.ClearCheckDesc() + return nil + case inspectionrecord.FieldFailReason: + m.ClearFailReason() + return nil case inspectionrecord.FieldInspector: m.ClearInspector() return nil @@ -2703,6 +3013,18 @@ func (m *InspectionRecordMutation) ResetField(name string) error { case inspectionrecord.FieldResultValue: m.ResetResultValue() return nil + case inspectionrecord.FieldInspectQty: + m.ResetInspectQty() + return nil + case inspectionrecord.FieldPassQty: + m.ResetPassQty() + return nil + case inspectionrecord.FieldCheckDesc: + m.ResetCheckDesc() + return nil + case inspectionrecord.FieldFailReason: + m.ResetFailReason() + return nil case inspectionrecord.FieldInspector: m.ResetInspector() return nil @@ -8069,6 +8391,9 @@ type OutboundOrderMutation struct { reviewer *string target_dock *string remark *string + box_no *string + box_sn_list *string + contract_no *string created_at *int64 addcreated_at *int64 clearedFields map[string]struct{} @@ -8787,6 +9112,153 @@ func (m *OutboundOrderMutation) ResetRemark() { delete(m.clearedFields, outboundorder.FieldRemark) } +// SetBoxNo sets the "box_no" field. +func (m *OutboundOrderMutation) SetBoxNo(s string) { + m.box_no = &s +} + +// BoxNo returns the value of the "box_no" field in the mutation. +func (m *OutboundOrderMutation) BoxNo() (r string, exists bool) { + v := m.box_no + if v == nil { + return + } + return *v, true +} + +// OldBoxNo returns the old "box_no" field's value of the OutboundOrder entity. +// If the OutboundOrder 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 *OutboundOrderMutation) OldBoxNo(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBoxNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBoxNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBoxNo: %w", err) + } + return oldValue.BoxNo, nil +} + +// ClearBoxNo clears the value of the "box_no" field. +func (m *OutboundOrderMutation) ClearBoxNo() { + m.box_no = nil + m.clearedFields[outboundorder.FieldBoxNo] = struct{}{} +} + +// BoxNoCleared returns if the "box_no" field was cleared in this mutation. +func (m *OutboundOrderMutation) BoxNoCleared() bool { + _, ok := m.clearedFields[outboundorder.FieldBoxNo] + return ok +} + +// ResetBoxNo resets all changes to the "box_no" field. +func (m *OutboundOrderMutation) ResetBoxNo() { + m.box_no = nil + delete(m.clearedFields, outboundorder.FieldBoxNo) +} + +// SetBoxSnList sets the "box_sn_list" field. +func (m *OutboundOrderMutation) SetBoxSnList(s string) { + m.box_sn_list = &s +} + +// BoxSnList returns the value of the "box_sn_list" field in the mutation. +func (m *OutboundOrderMutation) BoxSnList() (r string, exists bool) { + v := m.box_sn_list + if v == nil { + return + } + return *v, true +} + +// OldBoxSnList returns the old "box_sn_list" field's value of the OutboundOrder entity. +// If the OutboundOrder 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 *OutboundOrderMutation) OldBoxSnList(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldBoxSnList is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldBoxSnList requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBoxSnList: %w", err) + } + return oldValue.BoxSnList, nil +} + +// ClearBoxSnList clears the value of the "box_sn_list" field. +func (m *OutboundOrderMutation) ClearBoxSnList() { + m.box_sn_list = nil + m.clearedFields[outboundorder.FieldBoxSnList] = struct{}{} +} + +// BoxSnListCleared returns if the "box_sn_list" field was cleared in this mutation. +func (m *OutboundOrderMutation) BoxSnListCleared() bool { + _, ok := m.clearedFields[outboundorder.FieldBoxSnList] + return ok +} + +// ResetBoxSnList resets all changes to the "box_sn_list" field. +func (m *OutboundOrderMutation) ResetBoxSnList() { + m.box_sn_list = nil + delete(m.clearedFields, outboundorder.FieldBoxSnList) +} + +// SetContractNo sets the "contract_no" field. +func (m *OutboundOrderMutation) SetContractNo(s string) { + m.contract_no = &s +} + +// ContractNo returns the value of the "contract_no" field in the mutation. +func (m *OutboundOrderMutation) ContractNo() (r string, exists bool) { + v := m.contract_no + if v == nil { + return + } + return *v, true +} + +// OldContractNo returns the old "contract_no" field's value of the OutboundOrder entity. +// If the OutboundOrder 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 *OutboundOrderMutation) OldContractNo(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldContractNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldContractNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldContractNo: %w", err) + } + return oldValue.ContractNo, nil +} + +// ClearContractNo clears the value of the "contract_no" field. +func (m *OutboundOrderMutation) ClearContractNo() { + m.contract_no = nil + m.clearedFields[outboundorder.FieldContractNo] = struct{}{} +} + +// ContractNoCleared returns if the "contract_no" field was cleared in this mutation. +func (m *OutboundOrderMutation) ContractNoCleared() bool { + _, ok := m.clearedFields[outboundorder.FieldContractNo] + return ok +} + +// ResetContractNo resets all changes to the "contract_no" field. +func (m *OutboundOrderMutation) ResetContractNo() { + m.contract_no = nil + delete(m.clearedFields, outboundorder.FieldContractNo) +} + // SetCreatedAt sets the "created_at" field. func (m *OutboundOrderMutation) SetCreatedAt(i int64) { m.created_at = &i @@ -8877,7 +9349,7 @@ func (m *OutboundOrderMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *OutboundOrderMutation) Fields() []string { - fields := make([]string, 0, 14) + fields := make([]string, 0, 17) if m.outbound_no != nil { fields = append(fields, outboundorder.FieldOutboundNo) } @@ -8917,6 +9389,15 @@ func (m *OutboundOrderMutation) Fields() []string { if m.remark != nil { fields = append(fields, outboundorder.FieldRemark) } + if m.box_no != nil { + fields = append(fields, outboundorder.FieldBoxNo) + } + if m.box_sn_list != nil { + fields = append(fields, outboundorder.FieldBoxSnList) + } + if m.contract_no != nil { + fields = append(fields, outboundorder.FieldContractNo) + } if m.created_at != nil { fields = append(fields, outboundorder.FieldCreatedAt) } @@ -8954,6 +9435,12 @@ func (m *OutboundOrderMutation) Field(name string) (ent.Value, bool) { return m.TargetDock() case outboundorder.FieldRemark: return m.Remark() + case outboundorder.FieldBoxNo: + return m.BoxNo() + case outboundorder.FieldBoxSnList: + return m.BoxSnList() + case outboundorder.FieldContractNo: + return m.ContractNo() case outboundorder.FieldCreatedAt: return m.CreatedAt() } @@ -8991,6 +9478,12 @@ func (m *OutboundOrderMutation) OldField(ctx context.Context, name string) (ent. return m.OldTargetDock(ctx) case outboundorder.FieldRemark: return m.OldRemark(ctx) + case outboundorder.FieldBoxNo: + return m.OldBoxNo(ctx) + case outboundorder.FieldBoxSnList: + return m.OldBoxSnList(ctx) + case outboundorder.FieldContractNo: + return m.OldContractNo(ctx) case outboundorder.FieldCreatedAt: return m.OldCreatedAt(ctx) } @@ -9093,6 +9586,27 @@ func (m *OutboundOrderMutation) SetField(name string, value ent.Value) error { } m.SetRemark(v) return nil + case outboundorder.FieldBoxNo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBoxNo(v) + return nil + case outboundorder.FieldBoxSnList: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBoxSnList(v) + return nil + case outboundorder.FieldContractNo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetContractNo(v) + return nil case outboundorder.FieldCreatedAt: v, ok := value.(int64) if !ok { @@ -9193,6 +9707,15 @@ func (m *OutboundOrderMutation) ClearedFields() []string { if m.FieldCleared(outboundorder.FieldRemark) { fields = append(fields, outboundorder.FieldRemark) } + if m.FieldCleared(outboundorder.FieldBoxNo) { + fields = append(fields, outboundorder.FieldBoxNo) + } + if m.FieldCleared(outboundorder.FieldBoxSnList) { + fields = append(fields, outboundorder.FieldBoxSnList) + } + if m.FieldCleared(outboundorder.FieldContractNo) { + fields = append(fields, outboundorder.FieldContractNo) + } return fields } @@ -9231,6 +9754,15 @@ func (m *OutboundOrderMutation) ClearField(name string) error { case outboundorder.FieldRemark: m.ClearRemark() return nil + case outboundorder.FieldBoxNo: + m.ClearBoxNo() + return nil + case outboundorder.FieldBoxSnList: + m.ClearBoxSnList() + return nil + case outboundorder.FieldContractNo: + m.ClearContractNo() + return nil } return fmt.Errorf("unknown OutboundOrder nullable field %s", name) } @@ -9278,6 +9810,15 @@ func (m *OutboundOrderMutation) ResetField(name string) error { case outboundorder.FieldRemark: m.ResetRemark() return nil + case outboundorder.FieldBoxNo: + m.ResetBoxNo() + return nil + case outboundorder.FieldBoxSnList: + m.ResetBoxSnList() + return nil + case outboundorder.FieldContractNo: + m.ResetContractNo() + return nil case outboundorder.FieldCreatedAt: m.ResetCreatedAt() return nil @@ -9333,19 +9874,19 @@ func (m *OutboundOrderMutation) ResetEdge(name string) error { return fmt.Errorf("unknown OutboundOrder edge %s", name) } -// PackageBoxMutation represents an operation that mutates the PackageBox nodes in the graph. -type PackageBoxMutation struct { +// PermissionMutation represents an operation that mutates the Permission nodes in the graph. +type PermissionMutation struct { config op Op typ string id *int - box_no *string - sn_list *string - material_code *string - quantity *int - addquantity *int - operator *string - contract_no *string + code *string + name *string + _type *string + _path *string + icon *string + sort *int + addsort *int remark *string created_at *int64 addcreated_at *int64 @@ -9353,21 +9894,21 @@ type PackageBoxMutation struct { addupdated_at *int64 clearedFields map[string]struct{} done bool - oldValue func(context.Context) (*PackageBox, error) - predicates []predicate.PackageBox + oldValue func(context.Context) (*Permission, error) + predicates []predicate.Permission } -var _ ent.Mutation = (*PackageBoxMutation)(nil) +var _ ent.Mutation = (*PermissionMutation)(nil) -// packageboxOption allows management of the mutation configuration using functional options. -type packageboxOption func(*PackageBoxMutation) +// permissionOption allows management of the mutation configuration using functional options. +type permissionOption func(*PermissionMutation) -// newPackageBoxMutation creates new mutation for the PackageBox entity. -func newPackageBoxMutation(c config, op Op, opts ...packageboxOption) *PackageBoxMutation { - m := &PackageBoxMutation{ +// newPermissionMutation creates new mutation for the Permission entity. +func newPermissionMutation(c config, op Op, opts ...permissionOption) *PermissionMutation { + m := &PermissionMutation{ config: c, op: op, - typ: TypePackageBox, + typ: TypePermission, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -9376,20 +9917,20 @@ func newPackageBoxMutation(c config, op Op, opts ...packageboxOption) *PackageBo return m } -// withPackageBoxID sets the ID field of the mutation. -func withPackageBoxID(id int) packageboxOption { - return func(m *PackageBoxMutation) { +// withPermissionID sets the ID field of the mutation. +func withPermissionID(id int) permissionOption { + return func(m *PermissionMutation) { var ( err error once sync.Once - value *PackageBox + value *Permission ) - m.oldValue = func(ctx context.Context) (*PackageBox, error) { + m.oldValue = func(ctx context.Context) (*Permission, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { - value, err = m.Client().PackageBox.Get(ctx, id) + value, err = m.Client().Permission.Get(ctx, id) } }) return value, err @@ -9398,10 +9939,10 @@ func withPackageBoxID(id int) packageboxOption { } } -// withPackageBox sets the old PackageBox of the mutation. -func withPackageBox(node *PackageBox) packageboxOption { - return func(m *PackageBoxMutation) { - m.oldValue = func(context.Context) (*PackageBox, error) { +// withPermission sets the old Permission of the mutation. +func withPermission(node *Permission) permissionOption { + return func(m *PermissionMutation) { + m.oldValue = func(context.Context) (*Permission, error) { return node, nil } m.id = &node.ID @@ -9410,7 +9951,7 @@ func withPackageBox(node *PackageBox) packageboxOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m PackageBoxMutation) Client() *Client { +func (m PermissionMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -9418,7 +9959,7 @@ func (m PackageBoxMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m PackageBoxMutation) Tx() (*Tx, error) { +func (m PermissionMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } @@ -9429,7 +9970,7 @@ func (m PackageBoxMutation) Tx() (*Tx, error) { // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *PackageBoxMutation) ID() (id int, exists bool) { +func (m *PermissionMutation) ID() (id int, exists bool) { if m.id == nil { return } @@ -9440,7 +9981,7 @@ func (m *PackageBoxMutation) ID() (id int, exists bool) { // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. -func (m *PackageBoxMutation) IDs(ctx context.Context) ([]int, error) { +func (m *PermissionMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() @@ -9449,307 +9990,295 @@ func (m *PackageBoxMutation) IDs(ctx context.Context) ([]int, error) { } fallthrough case m.op.Is(OpUpdate | OpDelete): - return m.Client().PackageBox.Query().Where(m.predicates...).IDs(ctx) + return m.Client().Permission.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } -// SetBoxNo sets the "box_no" field. -func (m *PackageBoxMutation) SetBoxNo(s string) { - m.box_no = &s +// SetCode sets the "code" field. +func (m *PermissionMutation) SetCode(s string) { + m.code = &s } -// BoxNo returns the value of the "box_no" field in the mutation. -func (m *PackageBoxMutation) BoxNo() (r string, exists bool) { - v := m.box_no +// Code returns the value of the "code" field in the mutation. +func (m *PermissionMutation) Code() (r string, exists bool) { + v := m.code if v == nil { return } return *v, true } -// OldBoxNo returns the old "box_no" field's value of the PackageBox entity. -// If the PackageBox object wasn't provided to the builder, the object is fetched from the database. +// OldCode returns the old "code" field's value of the Permission entity. +// If the Permission 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 *PackageBoxMutation) OldBoxNo(ctx context.Context) (v string, err error) { +func (m *PermissionMutation) OldCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldBoxNo is only allowed on UpdateOne operations") + return v, errors.New("OldCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldBoxNo requires an ID field in the mutation") + return v, errors.New("OldCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldBoxNo: %w", err) + return v, fmt.Errorf("querying old value for OldCode: %w", err) } - return oldValue.BoxNo, nil + return oldValue.Code, nil } -// ResetBoxNo resets all changes to the "box_no" field. -func (m *PackageBoxMutation) ResetBoxNo() { - m.box_no = nil +// ResetCode resets all changes to the "code" field. +func (m *PermissionMutation) ResetCode() { + m.code = nil } -// SetSnList sets the "sn_list" field. -func (m *PackageBoxMutation) SetSnList(s string) { - m.sn_list = &s +// SetName sets the "name" field. +func (m *PermissionMutation) SetName(s string) { + m.name = &s } -// SnList returns the value of the "sn_list" field in the mutation. -func (m *PackageBoxMutation) SnList() (r string, exists bool) { - v := m.sn_list +// Name returns the value of the "name" field in the mutation. +func (m *PermissionMutation) Name() (r string, exists bool) { + v := m.name if v == nil { return } return *v, true } -// OldSnList returns the old "sn_list" field's value of the PackageBox entity. -// If the PackageBox object wasn't provided to the builder, the object is fetched from the database. +// OldName returns the old "name" field's value of the Permission entity. +// If the Permission 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 *PackageBoxMutation) OldSnList(ctx context.Context) (v string, err error) { +func (m *PermissionMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSnList is only allowed on UpdateOne operations") + return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSnList requires an ID field in the mutation") + return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldSnList: %w", err) + return v, fmt.Errorf("querying old value for OldName: %w", err) } - return oldValue.SnList, nil + return oldValue.Name, nil } -// ClearSnList clears the value of the "sn_list" field. -func (m *PackageBoxMutation) ClearSnList() { - m.sn_list = nil - m.clearedFields[packagebox.FieldSnList] = struct{}{} +// ResetName resets all changes to the "name" field. +func (m *PermissionMutation) ResetName() { + m.name = nil } -// SnListCleared returns if the "sn_list" field was cleared in this mutation. -func (m *PackageBoxMutation) SnListCleared() bool { - _, ok := m.clearedFields[packagebox.FieldSnList] +// SetType sets the "type" field. +func (m *PermissionMutation) SetType(s string) { + m._type = &s +} + +// GetType returns the value of the "type" field in the mutation. +func (m *PermissionMutation) GetType() (r string, exists bool) { + v := m._type + if v == nil { + return + } + return *v, true +} + +// OldType returns the old "type" field's value of the Permission entity. +// If the Permission 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 *PermissionMutation) OldType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldType: %w", err) + } + return oldValue.Type, nil +} + +// ResetType resets all changes to the "type" field. +func (m *PermissionMutation) ResetType() { + m._type = nil +} + +// SetPath sets the "path" field. +func (m *PermissionMutation) SetPath(s string) { + m._path = &s +} + +// Path returns the value of the "path" field in the mutation. +func (m *PermissionMutation) Path() (r string, exists bool) { + v := m._path + if v == nil { + return + } + return *v, true +} + +// OldPath returns the old "path" field's value of the Permission entity. +// If the Permission 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 *PermissionMutation) OldPath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPath: %w", err) + } + return oldValue.Path, nil +} + +// ClearPath clears the value of the "path" field. +func (m *PermissionMutation) ClearPath() { + m._path = nil + m.clearedFields[permission.FieldPath] = struct{}{} +} + +// PathCleared returns if the "path" field was cleared in this mutation. +func (m *PermissionMutation) PathCleared() bool { + _, ok := m.clearedFields[permission.FieldPath] return ok } -// ResetSnList resets all changes to the "sn_list" field. -func (m *PackageBoxMutation) ResetSnList() { - m.sn_list = nil - delete(m.clearedFields, packagebox.FieldSnList) +// ResetPath resets all changes to the "path" field. +func (m *PermissionMutation) ResetPath() { + m._path = nil + delete(m.clearedFields, permission.FieldPath) } -// SetMaterialCode sets the "material_code" field. -func (m *PackageBoxMutation) SetMaterialCode(s string) { - m.material_code = &s +// SetIcon sets the "icon" field. +func (m *PermissionMutation) SetIcon(s string) { + m.icon = &s } -// MaterialCode returns the value of the "material_code" field in the mutation. -func (m *PackageBoxMutation) MaterialCode() (r string, exists bool) { - v := m.material_code +// Icon returns the value of the "icon" field in the mutation. +func (m *PermissionMutation) Icon() (r string, exists bool) { + v := m.icon if v == nil { return } return *v, true } -// OldMaterialCode returns the old "material_code" field's value of the PackageBox entity. -// If the PackageBox object wasn't provided to the builder, the object is fetched from the database. +// OldIcon returns the old "icon" field's value of the Permission entity. +// If the Permission 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 *PackageBoxMutation) OldMaterialCode(ctx context.Context) (v string, err error) { +func (m *PermissionMutation) OldIcon(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldMaterialCode is only allowed on UpdateOne operations") + return v, errors.New("OldIcon is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldMaterialCode requires an ID field in the mutation") + return v, errors.New("OldIcon requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldMaterialCode: %w", err) + return v, fmt.Errorf("querying old value for OldIcon: %w", err) } - return oldValue.MaterialCode, nil + return oldValue.Icon, nil } -// ClearMaterialCode clears the value of the "material_code" field. -func (m *PackageBoxMutation) ClearMaterialCode() { - m.material_code = nil - m.clearedFields[packagebox.FieldMaterialCode] = struct{}{} +// ClearIcon clears the value of the "icon" field. +func (m *PermissionMutation) ClearIcon() { + m.icon = nil + m.clearedFields[permission.FieldIcon] = struct{}{} } -// MaterialCodeCleared returns if the "material_code" field was cleared in this mutation. -func (m *PackageBoxMutation) MaterialCodeCleared() bool { - _, ok := m.clearedFields[packagebox.FieldMaterialCode] +// IconCleared returns if the "icon" field was cleared in this mutation. +func (m *PermissionMutation) IconCleared() bool { + _, ok := m.clearedFields[permission.FieldIcon] return ok } -// ResetMaterialCode resets all changes to the "material_code" field. -func (m *PackageBoxMutation) ResetMaterialCode() { - m.material_code = nil - delete(m.clearedFields, packagebox.FieldMaterialCode) +// ResetIcon resets all changes to the "icon" field. +func (m *PermissionMutation) ResetIcon() { + m.icon = nil + delete(m.clearedFields, permission.FieldIcon) } -// SetQuantity sets the "quantity" field. -func (m *PackageBoxMutation) SetQuantity(i int) { - m.quantity = &i - m.addquantity = nil +// SetSort sets the "sort" field. +func (m *PermissionMutation) SetSort(i int) { + m.sort = &i + m.addsort = nil } -// Quantity returns the value of the "quantity" field in the mutation. -func (m *PackageBoxMutation) Quantity() (r int, exists bool) { - v := m.quantity +// Sort returns the value of the "sort" field in the mutation. +func (m *PermissionMutation) Sort() (r int, exists bool) { + v := m.sort if v == nil { return } return *v, true } -// OldQuantity returns the old "quantity" field's value of the PackageBox entity. -// If the PackageBox object wasn't provided to the builder, the object is fetched from the database. +// OldSort returns the old "sort" field's value of the Permission entity. +// If the Permission 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 *PackageBoxMutation) OldQuantity(ctx context.Context) (v int, err error) { +func (m *PermissionMutation) OldSort(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldQuantity is only allowed on UpdateOne operations") + return v, errors.New("OldSort is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldQuantity requires an ID field in the mutation") + return v, errors.New("OldSort requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldQuantity: %w", err) + return v, fmt.Errorf("querying old value for OldSort: %w", err) } - return oldValue.Quantity, nil + return oldValue.Sort, nil } -// AddQuantity adds i to the "quantity" field. -func (m *PackageBoxMutation) AddQuantity(i int) { - if m.addquantity != nil { - *m.addquantity += i +// AddSort adds i to the "sort" field. +func (m *PermissionMutation) AddSort(i int) { + if m.addsort != nil { + *m.addsort += i } else { - m.addquantity = &i + m.addsort = &i } } -// AddedQuantity returns the value that was added to the "quantity" field in this mutation. -func (m *PackageBoxMutation) AddedQuantity() (r int, exists bool) { - v := m.addquantity +// AddedSort returns the value that was added to the "sort" field in this mutation. +func (m *PermissionMutation) AddedSort() (r int, exists bool) { + v := m.addsort if v == nil { return } return *v, true } -// ResetQuantity resets all changes to the "quantity" field. -func (m *PackageBoxMutation) ResetQuantity() { - m.quantity = nil - m.addquantity = nil +// ClearSort clears the value of the "sort" field. +func (m *PermissionMutation) ClearSort() { + m.sort = nil + m.addsort = nil + m.clearedFields[permission.FieldSort] = struct{}{} } -// SetOperator sets the "operator" field. -func (m *PackageBoxMutation) SetOperator(s string) { - m.operator = &s -} - -// Operator returns the value of the "operator" field in the mutation. -func (m *PackageBoxMutation) Operator() (r string, exists bool) { - v := m.operator - if v == nil { - return - } - return *v, true -} - -// OldOperator returns the old "operator" field's value of the PackageBox entity. -// If the PackageBox 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 *PackageBoxMutation) OldOperator(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldOperator is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldOperator requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldOperator: %w", err) - } - return oldValue.Operator, nil -} - -// ClearOperator clears the value of the "operator" field. -func (m *PackageBoxMutation) ClearOperator() { - m.operator = nil - m.clearedFields[packagebox.FieldOperator] = struct{}{} -} - -// OperatorCleared returns if the "operator" field was cleared in this mutation. -func (m *PackageBoxMutation) OperatorCleared() bool { - _, ok := m.clearedFields[packagebox.FieldOperator] +// SortCleared returns if the "sort" field was cleared in this mutation. +func (m *PermissionMutation) SortCleared() bool { + _, ok := m.clearedFields[permission.FieldSort] return ok } -// ResetOperator resets all changes to the "operator" field. -func (m *PackageBoxMutation) ResetOperator() { - m.operator = nil - delete(m.clearedFields, packagebox.FieldOperator) -} - -// SetContractNo sets the "contract_no" field. -func (m *PackageBoxMutation) SetContractNo(s string) { - m.contract_no = &s -} - -// ContractNo returns the value of the "contract_no" field in the mutation. -func (m *PackageBoxMutation) ContractNo() (r string, exists bool) { - v := m.contract_no - if v == nil { - return - } - return *v, true -} - -// OldContractNo returns the old "contract_no" field's value of the PackageBox entity. -// If the PackageBox 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 *PackageBoxMutation) OldContractNo(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldContractNo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldContractNo requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldContractNo: %w", err) - } - return oldValue.ContractNo, nil -} - -// ClearContractNo clears the value of the "contract_no" field. -func (m *PackageBoxMutation) ClearContractNo() { - m.contract_no = nil - m.clearedFields[packagebox.FieldContractNo] = struct{}{} -} - -// ContractNoCleared returns if the "contract_no" field was cleared in this mutation. -func (m *PackageBoxMutation) ContractNoCleared() bool { - _, ok := m.clearedFields[packagebox.FieldContractNo] - return ok -} - -// ResetContractNo resets all changes to the "contract_no" field. -func (m *PackageBoxMutation) ResetContractNo() { - m.contract_no = nil - delete(m.clearedFields, packagebox.FieldContractNo) +// ResetSort resets all changes to the "sort" field. +func (m *PermissionMutation) ResetSort() { + m.sort = nil + m.addsort = nil + delete(m.clearedFields, permission.FieldSort) } // SetRemark sets the "remark" field. -func (m *PackageBoxMutation) SetRemark(s string) { +func (m *PermissionMutation) SetRemark(s string) { m.remark = &s } // Remark returns the value of the "remark" field in the mutation. -func (m *PackageBoxMutation) Remark() (r string, exists bool) { +func (m *PermissionMutation) Remark() (r string, exists bool) { v := m.remark if v == nil { return @@ -9757,10 +10286,10 @@ func (m *PackageBoxMutation) Remark() (r string, exists bool) { return *v, true } -// OldRemark returns the old "remark" field's value of the PackageBox entity. -// If the PackageBox object wasn't provided to the builder, the object is fetched from the database. +// OldRemark returns the old "remark" field's value of the Permission entity. +// If the Permission 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 *PackageBoxMutation) OldRemark(ctx context.Context) (v string, err error) { +func (m *PermissionMutation) OldRemark(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldRemark is only allowed on UpdateOne operations") } @@ -9775,31 +10304,31 @@ func (m *PackageBoxMutation) OldRemark(ctx context.Context) (v string, err error } // ClearRemark clears the value of the "remark" field. -func (m *PackageBoxMutation) ClearRemark() { +func (m *PermissionMutation) ClearRemark() { m.remark = nil - m.clearedFields[packagebox.FieldRemark] = struct{}{} + m.clearedFields[permission.FieldRemark] = struct{}{} } // RemarkCleared returns if the "remark" field was cleared in this mutation. -func (m *PackageBoxMutation) RemarkCleared() bool { - _, ok := m.clearedFields[packagebox.FieldRemark] +func (m *PermissionMutation) RemarkCleared() bool { + _, ok := m.clearedFields[permission.FieldRemark] return ok } // ResetRemark resets all changes to the "remark" field. -func (m *PackageBoxMutation) ResetRemark() { +func (m *PermissionMutation) ResetRemark() { m.remark = nil - delete(m.clearedFields, packagebox.FieldRemark) + delete(m.clearedFields, permission.FieldRemark) } // SetCreatedAt sets the "created_at" field. -func (m *PackageBoxMutation) SetCreatedAt(i int64) { +func (m *PermissionMutation) SetCreatedAt(i int64) { m.created_at = &i m.addcreated_at = nil } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *PackageBoxMutation) CreatedAt() (r int64, exists bool) { +func (m *PermissionMutation) CreatedAt() (r int64, exists bool) { v := m.created_at if v == nil { return @@ -9807,10 +10336,10 @@ func (m *PackageBoxMutation) CreatedAt() (r int64, exists bool) { return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the PackageBox entity. -// If the PackageBox object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the Permission entity. +// If the Permission 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 *PackageBoxMutation) OldCreatedAt(ctx context.Context) (v int64, err error) { +func (m *PermissionMutation) OldCreatedAt(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } @@ -9825,7 +10354,7 @@ func (m *PackageBoxMutation) OldCreatedAt(ctx context.Context) (v int64, err err } // AddCreatedAt adds i to the "created_at" field. -func (m *PackageBoxMutation) AddCreatedAt(i int64) { +func (m *PermissionMutation) AddCreatedAt(i int64) { if m.addcreated_at != nil { *m.addcreated_at += i } else { @@ -9834,7 +10363,7 @@ func (m *PackageBoxMutation) AddCreatedAt(i int64) { } // AddedCreatedAt returns the value that was added to the "created_at" field in this mutation. -func (m *PackageBoxMutation) AddedCreatedAt() (r int64, exists bool) { +func (m *PermissionMutation) AddedCreatedAt() (r int64, exists bool) { v := m.addcreated_at if v == nil { return @@ -9843,19 +10372,19 @@ func (m *PackageBoxMutation) AddedCreatedAt() (r int64, exists bool) { } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *PackageBoxMutation) ResetCreatedAt() { +func (m *PermissionMutation) ResetCreatedAt() { m.created_at = nil m.addcreated_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *PackageBoxMutation) SetUpdatedAt(i int64) { +func (m *PermissionMutation) SetUpdatedAt(i int64) { m.updated_at = &i m.addupdated_at = nil } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *PackageBoxMutation) UpdatedAt() (r int64, exists bool) { +func (m *PermissionMutation) UpdatedAt() (r int64, exists bool) { v := m.updated_at if v == nil { return @@ -9863,10 +10392,10 @@ func (m *PackageBoxMutation) UpdatedAt() (r int64, exists bool) { return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the PackageBox entity. -// If the PackageBox object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the Permission entity. +// If the Permission 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 *PackageBoxMutation) OldUpdatedAt(ctx context.Context) (v int64, err error) { +func (m *PermissionMutation) OldUpdatedAt(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") } @@ -9881,7 +10410,7 @@ func (m *PackageBoxMutation) OldUpdatedAt(ctx context.Context) (v int64, err err } // AddUpdatedAt adds i to the "updated_at" field. -func (m *PackageBoxMutation) AddUpdatedAt(i int64) { +func (m *PermissionMutation) AddUpdatedAt(i int64) { if m.addupdated_at != nil { *m.addupdated_at += i } else { @@ -9890,7 +10419,7 @@ func (m *PackageBoxMutation) AddUpdatedAt(i int64) { } // AddedUpdatedAt returns the value that was added to the "updated_at" field in this mutation. -func (m *PackageBoxMutation) AddedUpdatedAt() (r int64, exists bool) { +func (m *PermissionMutation) AddedUpdatedAt() (r int64, exists bool) { v := m.addupdated_at if v == nil { return @@ -9898,35 +10427,21 @@ func (m *PackageBoxMutation) AddedUpdatedAt() (r int64, exists bool) { return *v, true } -// ClearUpdatedAt clears the value of the "updated_at" field. -func (m *PackageBoxMutation) ClearUpdatedAt() { - m.updated_at = nil - m.addupdated_at = nil - m.clearedFields[packagebox.FieldUpdatedAt] = struct{}{} -} - -// UpdatedAtCleared returns if the "updated_at" field was cleared in this mutation. -func (m *PackageBoxMutation) UpdatedAtCleared() bool { - _, ok := m.clearedFields[packagebox.FieldUpdatedAt] - return ok -} - // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *PackageBoxMutation) ResetUpdatedAt() { +func (m *PermissionMutation) ResetUpdatedAt() { m.updated_at = nil m.addupdated_at = nil - delete(m.clearedFields, packagebox.FieldUpdatedAt) } -// Where appends a list predicates to the PackageBoxMutation builder. -func (m *PackageBoxMutation) Where(ps ...predicate.PackageBox) { +// Where appends a list predicates to the PermissionMutation builder. +func (m *PermissionMutation) Where(ps ...predicate.Permission) { m.predicates = append(m.predicates, ps...) } -// WhereP appends storage-level predicates to the PackageBoxMutation builder. Using this method, +// WhereP appends storage-level predicates to the PermissionMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. -func (m *PackageBoxMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.PackageBox, len(ps)) +func (m *PermissionMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Permission, len(ps)) for i := range ps { p[i] = ps[i] } @@ -9934,51 +10449,51 @@ func (m *PackageBoxMutation) WhereP(ps ...func(*sql.Selector)) { } // Op returns the operation name. -func (m *PackageBoxMutation) Op() Op { +func (m *PermissionMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. -func (m *PackageBoxMutation) SetOp(op Op) { +func (m *PermissionMutation) SetOp(op Op) { m.op = op } -// Type returns the node type of this mutation (PackageBox). -func (m *PackageBoxMutation) Type() string { +// Type returns the node type of this mutation (Permission). +func (m *PermissionMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). -func (m *PackageBoxMutation) Fields() []string { +func (m *PermissionMutation) Fields() []string { fields := make([]string, 0, 9) - if m.box_no != nil { - fields = append(fields, packagebox.FieldBoxNo) + if m.code != nil { + fields = append(fields, permission.FieldCode) } - if m.sn_list != nil { - fields = append(fields, packagebox.FieldSnList) + if m.name != nil { + fields = append(fields, permission.FieldName) } - if m.material_code != nil { - fields = append(fields, packagebox.FieldMaterialCode) + if m._type != nil { + fields = append(fields, permission.FieldType) } - if m.quantity != nil { - fields = append(fields, packagebox.FieldQuantity) + if m._path != nil { + fields = append(fields, permission.FieldPath) } - if m.operator != nil { - fields = append(fields, packagebox.FieldOperator) + if m.icon != nil { + fields = append(fields, permission.FieldIcon) } - if m.contract_no != nil { - fields = append(fields, packagebox.FieldContractNo) + if m.sort != nil { + fields = append(fields, permission.FieldSort) } if m.remark != nil { - fields = append(fields, packagebox.FieldRemark) + fields = append(fields, permission.FieldRemark) } if m.created_at != nil { - fields = append(fields, packagebox.FieldCreatedAt) + fields = append(fields, permission.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, packagebox.FieldUpdatedAt) + fields = append(fields, permission.FieldUpdatedAt) } return fields } @@ -9986,25 +10501,25 @@ func (m *PackageBoxMutation) Fields() []string { // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *PackageBoxMutation) Field(name string) (ent.Value, bool) { +func (m *PermissionMutation) Field(name string) (ent.Value, bool) { switch name { - case packagebox.FieldBoxNo: - return m.BoxNo() - case packagebox.FieldSnList: - return m.SnList() - case packagebox.FieldMaterialCode: - return m.MaterialCode() - case packagebox.FieldQuantity: - return m.Quantity() - case packagebox.FieldOperator: - return m.Operator() - case packagebox.FieldContractNo: - return m.ContractNo() - case packagebox.FieldRemark: + case permission.FieldCode: + return m.Code() + case permission.FieldName: + return m.Name() + case permission.FieldType: + return m.GetType() + case permission.FieldPath: + return m.Path() + case permission.FieldIcon: + return m.Icon() + case permission.FieldSort: + return m.Sort() + case permission.FieldRemark: return m.Remark() - case packagebox.FieldCreatedAt: + case permission.FieldCreatedAt: return m.CreatedAt() - case packagebox.FieldUpdatedAt: + case permission.FieldUpdatedAt: return m.UpdatedAt() } return nil, false @@ -10013,92 +10528,92 @@ func (m *PackageBoxMutation) Field(name string) (ent.Value, bool) { // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. -func (m *PackageBoxMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *PermissionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case packagebox.FieldBoxNo: - return m.OldBoxNo(ctx) - case packagebox.FieldSnList: - return m.OldSnList(ctx) - case packagebox.FieldMaterialCode: - return m.OldMaterialCode(ctx) - case packagebox.FieldQuantity: - return m.OldQuantity(ctx) - case packagebox.FieldOperator: - return m.OldOperator(ctx) - case packagebox.FieldContractNo: - return m.OldContractNo(ctx) - case packagebox.FieldRemark: + case permission.FieldCode: + return m.OldCode(ctx) + case permission.FieldName: + return m.OldName(ctx) + case permission.FieldType: + return m.OldType(ctx) + case permission.FieldPath: + return m.OldPath(ctx) + case permission.FieldIcon: + return m.OldIcon(ctx) + case permission.FieldSort: + return m.OldSort(ctx) + case permission.FieldRemark: return m.OldRemark(ctx) - case packagebox.FieldCreatedAt: + case permission.FieldCreatedAt: return m.OldCreatedAt(ctx) - case packagebox.FieldUpdatedAt: + case permission.FieldUpdatedAt: return m.OldUpdatedAt(ctx) } - return nil, fmt.Errorf("unknown PackageBox field %s", name) + return nil, fmt.Errorf("unknown Permission field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *PackageBoxMutation) SetField(name string, value ent.Value) error { +func (m *PermissionMutation) SetField(name string, value ent.Value) error { switch name { - case packagebox.FieldBoxNo: + case permission.FieldCode: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetBoxNo(v) + m.SetCode(v) return nil - case packagebox.FieldSnList: + case permission.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSnList(v) + m.SetName(v) return nil - case packagebox.FieldMaterialCode: + case permission.FieldType: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetMaterialCode(v) + m.SetType(v) return nil - case packagebox.FieldQuantity: + case permission.FieldPath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPath(v) + return nil + case permission.FieldIcon: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIcon(v) + return nil + case permission.FieldSort: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetQuantity(v) + m.SetSort(v) return nil - case packagebox.FieldOperator: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetOperator(v) - return nil - case packagebox.FieldContractNo: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetContractNo(v) - return nil - case packagebox.FieldRemark: + case permission.FieldRemark: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetRemark(v) return nil - case packagebox.FieldCreatedAt: + case permission.FieldCreatedAt: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil - case packagebox.FieldUpdatedAt: + case permission.FieldUpdatedAt: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) @@ -10106,21 +10621,21 @@ func (m *PackageBoxMutation) SetField(name string, value ent.Value) error { m.SetUpdatedAt(v) return nil } - return fmt.Errorf("unknown PackageBox field %s", name) + return fmt.Errorf("unknown Permission field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *PackageBoxMutation) AddedFields() []string { +func (m *PermissionMutation) AddedFields() []string { var fields []string - if m.addquantity != nil { - fields = append(fields, packagebox.FieldQuantity) + if m.addsort != nil { + fields = append(fields, permission.FieldSort) } if m.addcreated_at != nil { - fields = append(fields, packagebox.FieldCreatedAt) + fields = append(fields, permission.FieldCreatedAt) } if m.addupdated_at != nil { - fields = append(fields, packagebox.FieldUpdatedAt) + fields = append(fields, permission.FieldUpdatedAt) } return fields } @@ -10128,13 +10643,13 @@ func (m *PackageBoxMutation) AddedFields() []string { // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *PackageBoxMutation) AddedField(name string) (ent.Value, bool) { +func (m *PermissionMutation) AddedField(name string) (ent.Value, bool) { switch name { - case packagebox.FieldQuantity: - return m.AddedQuantity() - case packagebox.FieldCreatedAt: + case permission.FieldSort: + return m.AddedSort() + case permission.FieldCreatedAt: return m.AddedCreatedAt() - case packagebox.FieldUpdatedAt: + case permission.FieldUpdatedAt: return m.AddedUpdatedAt() } return nil, false @@ -10143,23 +10658,23 @@ func (m *PackageBoxMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *PackageBoxMutation) AddField(name string, value ent.Value) error { +func (m *PermissionMutation) AddField(name string, value ent.Value) error { switch name { - case packagebox.FieldQuantity: + case permission.FieldSort: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.AddQuantity(v) + m.AddSort(v) return nil - case packagebox.FieldCreatedAt: + case permission.FieldCreatedAt: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddCreatedAt(v) return nil - case packagebox.FieldUpdatedAt: + case permission.FieldUpdatedAt: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) @@ -10167,148 +10682,859 @@ func (m *PackageBoxMutation) AddField(name string, value ent.Value) error { m.AddUpdatedAt(v) return nil } - return fmt.Errorf("unknown PackageBox numeric field %s", name) + return fmt.Errorf("unknown Permission numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *PackageBoxMutation) ClearedFields() []string { +func (m *PermissionMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(packagebox.FieldSnList) { - fields = append(fields, packagebox.FieldSnList) + if m.FieldCleared(permission.FieldPath) { + fields = append(fields, permission.FieldPath) } - if m.FieldCleared(packagebox.FieldMaterialCode) { - fields = append(fields, packagebox.FieldMaterialCode) + if m.FieldCleared(permission.FieldIcon) { + fields = append(fields, permission.FieldIcon) } - if m.FieldCleared(packagebox.FieldOperator) { - fields = append(fields, packagebox.FieldOperator) + if m.FieldCleared(permission.FieldSort) { + fields = append(fields, permission.FieldSort) } - if m.FieldCleared(packagebox.FieldContractNo) { - fields = append(fields, packagebox.FieldContractNo) - } - if m.FieldCleared(packagebox.FieldRemark) { - fields = append(fields, packagebox.FieldRemark) - } - if m.FieldCleared(packagebox.FieldUpdatedAt) { - fields = append(fields, packagebox.FieldUpdatedAt) + if m.FieldCleared(permission.FieldRemark) { + fields = append(fields, permission.FieldRemark) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *PackageBoxMutation) FieldCleared(name string) bool { +func (m *PermissionMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *PackageBoxMutation) ClearField(name string) error { +func (m *PermissionMutation) ClearField(name string) error { switch name { - case packagebox.FieldSnList: - m.ClearSnList() + case permission.FieldPath: + m.ClearPath() return nil - case packagebox.FieldMaterialCode: - m.ClearMaterialCode() + case permission.FieldIcon: + m.ClearIcon() return nil - case packagebox.FieldOperator: - m.ClearOperator() + case permission.FieldSort: + m.ClearSort() return nil - case packagebox.FieldContractNo: - m.ClearContractNo() - return nil - case packagebox.FieldRemark: + case permission.FieldRemark: m.ClearRemark() return nil - case packagebox.FieldUpdatedAt: - m.ClearUpdatedAt() - return nil } - return fmt.Errorf("unknown PackageBox nullable field %s", name) + return fmt.Errorf("unknown Permission nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *PackageBoxMutation) ResetField(name string) error { +func (m *PermissionMutation) ResetField(name string) error { switch name { - case packagebox.FieldBoxNo: - m.ResetBoxNo() + case permission.FieldCode: + m.ResetCode() return nil - case packagebox.FieldSnList: - m.ResetSnList() + case permission.FieldName: + m.ResetName() return nil - case packagebox.FieldMaterialCode: - m.ResetMaterialCode() + case permission.FieldType: + m.ResetType() return nil - case packagebox.FieldQuantity: - m.ResetQuantity() + case permission.FieldPath: + m.ResetPath() return nil - case packagebox.FieldOperator: - m.ResetOperator() + case permission.FieldIcon: + m.ResetIcon() return nil - case packagebox.FieldContractNo: - m.ResetContractNo() + case permission.FieldSort: + m.ResetSort() return nil - case packagebox.FieldRemark: + case permission.FieldRemark: m.ResetRemark() return nil - case packagebox.FieldCreatedAt: + case permission.FieldCreatedAt: m.ResetCreatedAt() return nil - case packagebox.FieldUpdatedAt: + case permission.FieldUpdatedAt: m.ResetUpdatedAt() return nil } - return fmt.Errorf("unknown PackageBox field %s", name) + return fmt.Errorf("unknown Permission field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *PackageBoxMutation) AddedEdges() []string { +func (m *PermissionMutation) AddedEdges() []string { edges := make([]string, 0, 0) return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *PackageBoxMutation) AddedIDs(name string) []ent.Value { +func (m *PermissionMutation) AddedIDs(name string) []ent.Value { return nil } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *PackageBoxMutation) RemovedEdges() []string { +func (m *PermissionMutation) RemovedEdges() []string { edges := make([]string, 0, 0) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *PackageBoxMutation) RemovedIDs(name string) []ent.Value { +func (m *PermissionMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *PackageBoxMutation) ClearedEdges() []string { +func (m *PermissionMutation) ClearedEdges() []string { edges := make([]string, 0, 0) return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *PackageBoxMutation) EdgeCleared(name string) bool { +func (m *PermissionMutation) EdgeCleared(name string) bool { return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. -func (m *PackageBoxMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown PackageBox unique edge %s", name) +func (m *PermissionMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown Permission unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. -func (m *PackageBoxMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown PackageBox edge %s", name) +func (m *PermissionMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown Permission edge %s", name) +} + +// RoleMutation represents an operation that mutates the Role nodes in the graph. +type RoleMutation struct { + config + op Op + typ string + id *int + name *string + code *string + remark *string + permission_codes *[]string + appendpermission_codes []string + created_at *int64 + addcreated_at *int64 + updated_at *int64 + addupdated_at *int64 + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*Role, error) + predicates []predicate.Role +} + +var _ ent.Mutation = (*RoleMutation)(nil) + +// roleOption allows management of the mutation configuration using functional options. +type roleOption func(*RoleMutation) + +// newRoleMutation creates new mutation for the Role entity. +func newRoleMutation(c config, op Op, opts ...roleOption) *RoleMutation { + m := &RoleMutation{ + config: c, + op: op, + typ: TypeRole, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withRoleID sets the ID field of the mutation. +func withRoleID(id int) roleOption { + return func(m *RoleMutation) { + var ( + err error + once sync.Once + value *Role + ) + m.oldValue = func(ctx context.Context) (*Role, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Role.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withRole sets the old Role of the mutation. +func withRole(node *Role) roleOption { + return func(m *RoleMutation) { + m.oldValue = func(context.Context) (*Role, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m RoleMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m RoleMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *RoleMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *RoleMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Role.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetName sets the "name" field. +func (m *RoleMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *RoleMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the Role entity. +// If the Role 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 *RoleMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *RoleMutation) ResetName() { + m.name = nil +} + +// SetCode sets the "code" field. +func (m *RoleMutation) SetCode(s string) { + m.code = &s +} + +// Code returns the value of the "code" field in the mutation. +func (m *RoleMutation) Code() (r string, exists bool) { + v := m.code + if v == nil { + return + } + return *v, true +} + +// OldCode returns the old "code" field's value of the Role entity. +// If the Role 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 *RoleMutation) OldCode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCode: %w", err) + } + return oldValue.Code, nil +} + +// ResetCode resets all changes to the "code" field. +func (m *RoleMutation) ResetCode() { + m.code = nil +} + +// SetRemark sets the "remark" field. +func (m *RoleMutation) SetRemark(s string) { + m.remark = &s +} + +// Remark returns the value of the "remark" field in the mutation. +func (m *RoleMutation) Remark() (r string, exists bool) { + v := m.remark + if v == nil { + return + } + return *v, true +} + +// OldRemark returns the old "remark" field's value of the Role entity. +// If the Role 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 *RoleMutation) OldRemark(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRemark is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRemark requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRemark: %w", err) + } + return oldValue.Remark, nil +} + +// ClearRemark clears the value of the "remark" field. +func (m *RoleMutation) ClearRemark() { + m.remark = nil + m.clearedFields[role.FieldRemark] = struct{}{} +} + +// RemarkCleared returns if the "remark" field was cleared in this mutation. +func (m *RoleMutation) RemarkCleared() bool { + _, ok := m.clearedFields[role.FieldRemark] + return ok +} + +// ResetRemark resets all changes to the "remark" field. +func (m *RoleMutation) ResetRemark() { + m.remark = nil + delete(m.clearedFields, role.FieldRemark) +} + +// SetPermissionCodes sets the "permission_codes" field. +func (m *RoleMutation) SetPermissionCodes(s []string) { + m.permission_codes = &s + m.appendpermission_codes = nil +} + +// PermissionCodes returns the value of the "permission_codes" field in the mutation. +func (m *RoleMutation) PermissionCodes() (r []string, exists bool) { + v := m.permission_codes + if v == nil { + return + } + return *v, true +} + +// OldPermissionCodes returns the old "permission_codes" field's value of the Role entity. +// If the Role 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 *RoleMutation) OldPermissionCodes(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPermissionCodes is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPermissionCodes requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPermissionCodes: %w", err) + } + return oldValue.PermissionCodes, nil +} + +// AppendPermissionCodes adds s to the "permission_codes" field. +func (m *RoleMutation) AppendPermissionCodes(s []string) { + m.appendpermission_codes = append(m.appendpermission_codes, s...) +} + +// AppendedPermissionCodes returns the list of values that were appended to the "permission_codes" field in this mutation. +func (m *RoleMutation) AppendedPermissionCodes() ([]string, bool) { + if len(m.appendpermission_codes) == 0 { + return nil, false + } + return m.appendpermission_codes, true +} + +// ClearPermissionCodes clears the value of the "permission_codes" field. +func (m *RoleMutation) ClearPermissionCodes() { + m.permission_codes = nil + m.appendpermission_codes = nil + m.clearedFields[role.FieldPermissionCodes] = struct{}{} +} + +// PermissionCodesCleared returns if the "permission_codes" field was cleared in this mutation. +func (m *RoleMutation) PermissionCodesCleared() bool { + _, ok := m.clearedFields[role.FieldPermissionCodes] + return ok +} + +// ResetPermissionCodes resets all changes to the "permission_codes" field. +func (m *RoleMutation) ResetPermissionCodes() { + m.permission_codes = nil + m.appendpermission_codes = nil + delete(m.clearedFields, role.FieldPermissionCodes) +} + +// SetCreatedAt sets the "created_at" field. +func (m *RoleMutation) SetCreatedAt(i int64) { + m.created_at = &i + m.addcreated_at = nil +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *RoleMutation) CreatedAt() (r int64, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Role entity. +// If the Role 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 *RoleMutation) OldCreatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// AddCreatedAt adds i to the "created_at" field. +func (m *RoleMutation) AddCreatedAt(i int64) { + if m.addcreated_at != nil { + *m.addcreated_at += i + } else { + m.addcreated_at = &i + } +} + +// AddedCreatedAt returns the value that was added to the "created_at" field in this mutation. +func (m *RoleMutation) AddedCreatedAt() (r int64, exists bool) { + v := m.addcreated_at + if v == nil { + return + } + return *v, true +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *RoleMutation) ResetCreatedAt() { + m.created_at = nil + m.addcreated_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *RoleMutation) SetUpdatedAt(i int64) { + m.updated_at = &i + m.addupdated_at = nil +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *RoleMutation) UpdatedAt() (r int64, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Role entity. +// If the Role 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 *RoleMutation) OldUpdatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// AddUpdatedAt adds i to the "updated_at" field. +func (m *RoleMutation) AddUpdatedAt(i int64) { + if m.addupdated_at != nil { + *m.addupdated_at += i + } else { + m.addupdated_at = &i + } +} + +// AddedUpdatedAt returns the value that was added to the "updated_at" field in this mutation. +func (m *RoleMutation) AddedUpdatedAt() (r int64, exists bool) { + v := m.addupdated_at + if v == nil { + return + } + return *v, true +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *RoleMutation) ResetUpdatedAt() { + m.updated_at = nil + m.addupdated_at = nil +} + +// Where appends a list predicates to the RoleMutation builder. +func (m *RoleMutation) Where(ps ...predicate.Role) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the RoleMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *RoleMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Role, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *RoleMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *RoleMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Role). +func (m *RoleMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *RoleMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.name != nil { + fields = append(fields, role.FieldName) + } + if m.code != nil { + fields = append(fields, role.FieldCode) + } + if m.remark != nil { + fields = append(fields, role.FieldRemark) + } + if m.permission_codes != nil { + fields = append(fields, role.FieldPermissionCodes) + } + if m.created_at != nil { + fields = append(fields, role.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, role.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *RoleMutation) Field(name string) (ent.Value, bool) { + switch name { + case role.FieldName: + return m.Name() + case role.FieldCode: + return m.Code() + case role.FieldRemark: + return m.Remark() + case role.FieldPermissionCodes: + return m.PermissionCodes() + case role.FieldCreatedAt: + return m.CreatedAt() + case role.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *RoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case role.FieldName: + return m.OldName(ctx) + case role.FieldCode: + return m.OldCode(ctx) + case role.FieldRemark: + return m.OldRemark(ctx) + case role.FieldPermissionCodes: + return m.OldPermissionCodes(ctx) + case role.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case role.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown Role field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *RoleMutation) SetField(name string, value ent.Value) error { + switch name { + case role.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case role.FieldCode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCode(v) + return nil + case role.FieldRemark: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRemark(v) + return nil + case role.FieldPermissionCodes: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPermissionCodes(v) + return nil + case role.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case role.FieldUpdatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Role field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *RoleMutation) AddedFields() []string { + var fields []string + if m.addcreated_at != nil { + fields = append(fields, role.FieldCreatedAt) + } + if m.addupdated_at != nil { + fields = append(fields, role.FieldUpdatedAt) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *RoleMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case role.FieldCreatedAt: + return m.AddedCreatedAt() + case role.FieldUpdatedAt: + return m.AddedUpdatedAt() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *RoleMutation) AddField(name string, value ent.Value) error { + switch name { + case role.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCreatedAt(v) + return nil + case role.FieldUpdatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown Role numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *RoleMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(role.FieldRemark) { + fields = append(fields, role.FieldRemark) + } + if m.FieldCleared(role.FieldPermissionCodes) { + fields = append(fields, role.FieldPermissionCodes) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *RoleMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *RoleMutation) ClearField(name string) error { + switch name { + case role.FieldRemark: + m.ClearRemark() + return nil + case role.FieldPermissionCodes: + m.ClearPermissionCodes() + return nil + } + return fmt.Errorf("unknown Role nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *RoleMutation) ResetField(name string) error { + switch name { + case role.FieldName: + m.ResetName() + return nil + case role.FieldCode: + m.ResetCode() + return nil + case role.FieldRemark: + m.ResetRemark() + return nil + case role.FieldPermissionCodes: + m.ResetPermissionCodes() + return nil + case role.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case role.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown Role field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *RoleMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *RoleMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *RoleMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *RoleMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *RoleMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *RoleMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *RoleMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown Role unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *RoleMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown Role edge %s", name) } // SemiFinishedMutation represents an operation that mutates the SemiFinished nodes in the graph. @@ -12988,6 +14214,8 @@ type UserMutation struct { password *string real_name *string role *string + role_id *int + addrole_id *int dept *string phone *string is_active *bool @@ -13258,6 +14486,76 @@ func (m *UserMutation) ResetRole() { m.role = nil } +// SetRoleID sets the "role_id" field. +func (m *UserMutation) SetRoleID(i int) { + m.role_id = &i + m.addrole_id = nil +} + +// RoleID returns the value of the "role_id" field in the mutation. +func (m *UserMutation) RoleID() (r int, exists bool) { + v := m.role_id + if v == nil { + return + } + return *v, true +} + +// OldRoleID returns the old "role_id" field's value of the User entity. +// If the User 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 *UserMutation) OldRoleID(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRoleID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRoleID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRoleID: %w", err) + } + return oldValue.RoleID, nil +} + +// AddRoleID adds i to the "role_id" field. +func (m *UserMutation) AddRoleID(i int) { + if m.addrole_id != nil { + *m.addrole_id += i + } else { + m.addrole_id = &i + } +} + +// AddedRoleID returns the value that was added to the "role_id" field in this mutation. +func (m *UserMutation) AddedRoleID() (r int, exists bool) { + v := m.addrole_id + if v == nil { + return + } + return *v, true +} + +// ClearRoleID clears the value of the "role_id" field. +func (m *UserMutation) ClearRoleID() { + m.role_id = nil + m.addrole_id = nil + m.clearedFields[user.FieldRoleID] = struct{}{} +} + +// RoleIDCleared returns if the "role_id" field was cleared in this mutation. +func (m *UserMutation) RoleIDCleared() bool { + _, ok := m.clearedFields[user.FieldRoleID] + return ok +} + +// ResetRoleID resets all changes to the "role_id" field. +func (m *UserMutation) ResetRoleID() { + m.role_id = nil + m.addrole_id = nil + delete(m.clearedFields, user.FieldRoleID) +} + // SetDept sets the "dept" field. func (m *UserMutation) SetDept(s string) { m.dept = &s @@ -13608,7 +14906,7 @@ func (m *UserMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 10) + fields := make([]string, 0, 11) if m.username != nil { fields = append(fields, user.FieldUsername) } @@ -13621,6 +14919,9 @@ func (m *UserMutation) Fields() []string { if m.role != nil { fields = append(fields, user.FieldRole) } + if m.role_id != nil { + fields = append(fields, user.FieldRoleID) + } if m.dept != nil { fields = append(fields, user.FieldDept) } @@ -13655,6 +14956,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { return m.RealName() case user.FieldRole: return m.Role() + case user.FieldRoleID: + return m.RoleID() case user.FieldDept: return m.Dept() case user.FieldPhone: @@ -13684,6 +14987,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldRealName(ctx) case user.FieldRole: return m.OldRole(ctx) + case user.FieldRoleID: + return m.OldRoleID(ctx) case user.FieldDept: return m.OldDept(ctx) case user.FieldPhone: @@ -13733,6 +15038,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetRole(v) return nil + case user.FieldRoleID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRoleID(v) + return nil case user.FieldDept: v, ok := value.(string) if !ok { @@ -13783,6 +15095,9 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { // this mutation. func (m *UserMutation) AddedFields() []string { var fields []string + if m.addrole_id != nil { + fields = append(fields, user.FieldRoleID) + } if m.addlast_login_at != nil { fields = append(fields, user.FieldLastLoginAt) } @@ -13800,6 +15115,8 @@ func (m *UserMutation) AddedFields() []string { // was not set, or was not defined in the schema. func (m *UserMutation) AddedField(name string) (ent.Value, bool) { switch name { + case user.FieldRoleID: + return m.AddedRoleID() case user.FieldLastLoginAt: return m.AddedLastLoginAt() case user.FieldCreatedAt: @@ -13815,6 +15132,13 @@ func (m *UserMutation) AddedField(name string) (ent.Value, bool) { // type. func (m *UserMutation) AddField(name string, value ent.Value) error { switch name { + case user.FieldRoleID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddRoleID(v) + return nil case user.FieldLastLoginAt: v, ok := value.(int64) if !ok { @@ -13847,6 +15171,9 @@ func (m *UserMutation) ClearedFields() []string { if m.FieldCleared(user.FieldRealName) { fields = append(fields, user.FieldRealName) } + if m.FieldCleared(user.FieldRoleID) { + fields = append(fields, user.FieldRoleID) + } if m.FieldCleared(user.FieldDept) { fields = append(fields, user.FieldDept) } @@ -13873,6 +15200,9 @@ func (m *UserMutation) ClearField(name string) error { case user.FieldRealName: m.ClearRealName() return nil + case user.FieldRoleID: + m.ClearRoleID() + return nil case user.FieldDept: m.ClearDept() return nil @@ -13902,6 +15232,9 @@ func (m *UserMutation) ResetField(name string) error { case user.FieldRole: m.ResetRole() return nil + case user.FieldRoleID: + m.ResetRoleID() + return nil case user.FieldDept: m.ResetDept() return nil diff --git a/bj_power_wms/ent/outboundorder.go b/bj_power_wms/ent/outboundorder.go index 00b1808..6fd1cb6 100644 --- a/bj_power_wms/ent/outboundorder.go +++ b/bj_power_wms/ent/outboundorder.go @@ -26,13 +26,13 @@ type OutboundOrder struct { MaterialCode string `json:"materialCode,omitempty"` // 物料名称(冗余) MaterialName string `json:"materialName,omitempty"` - // ManageMode holds the value of the "manage_mode" field. + // 管理粒度 1批次/2序列号 ManageMode int `json:"manageMode,omitempty"` // 批次号(结构件) BatchNo string `json:"batchNo,omitempty"` // 出库区域 ZoneCode string `json:"zoneCode,omitempty"` - // 数量 + // 本次出库总数量 Quantity int `json:"quantity,omitempty"` // 操作人 Operator string `json:"operator,omitempty"` @@ -42,7 +42,13 @@ type OutboundOrder struct { TargetDock string `json:"targetDock,omitempty"` // 备注 Remark string `json:"remark,omitempty"` - // CreatedAt holds the value of the "created_at" field. + // 箱号(装箱出库时填写,用于整箱发货追溯) + BoxNo string `json:"boxNo,omitempty"` + // 装箱 SN 清单(JSON 数组字符串) + BoxSnList string `json:"boxSnList,omitempty"` + // 合同号(装箱选填) + ContractNo string `json:"contractNo,omitempty"` + // 创建时间 CreatedAt int64 `json:"createdAt,omitempty"` selectValues sql.SelectValues } @@ -54,7 +60,7 @@ func (*OutboundOrder) scanValues(columns []string) ([]any, error) { switch columns[i] { case outboundorder.FieldID, outboundorder.FieldManageMode, outboundorder.FieldQuantity, outboundorder.FieldCreatedAt: values[i] = new(sql.NullInt64) - case outboundorder.FieldOutboundNo, outboundorder.FieldOutboundType, outboundorder.FieldOrderNo, outboundorder.FieldMaterialCode, outboundorder.FieldMaterialName, outboundorder.FieldBatchNo, outboundorder.FieldZoneCode, outboundorder.FieldOperator, outboundorder.FieldReviewer, outboundorder.FieldTargetDock, outboundorder.FieldRemark: + case outboundorder.FieldOutboundNo, outboundorder.FieldOutboundType, outboundorder.FieldOrderNo, outboundorder.FieldMaterialCode, outboundorder.FieldMaterialName, outboundorder.FieldBatchNo, outboundorder.FieldZoneCode, outboundorder.FieldOperator, outboundorder.FieldReviewer, outboundorder.FieldTargetDock, outboundorder.FieldRemark, outboundorder.FieldBoxNo, outboundorder.FieldBoxSnList, outboundorder.FieldContractNo: values[i] = new(sql.NullString) default: values[i] = new(sql.UnknownType) @@ -155,6 +161,24 @@ func (_m *OutboundOrder) assignValues(columns []string, values []any) error { } else if value.Valid { _m.Remark = value.String } + case outboundorder.FieldBoxNo: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field box_no", values[i]) + } else if value.Valid { + _m.BoxNo = value.String + } + case outboundorder.FieldBoxSnList: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field box_sn_list", values[i]) + } else if value.Valid { + _m.BoxSnList = value.String + } + case outboundorder.FieldContractNo: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field contract_no", values[i]) + } else if value.Valid { + _m.ContractNo = value.String + } case outboundorder.FieldCreatedAt: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) @@ -236,6 +260,15 @@ func (_m *OutboundOrder) String() string { builder.WriteString("remark=") builder.WriteString(_m.Remark) builder.WriteString(", ") + builder.WriteString("box_no=") + builder.WriteString(_m.BoxNo) + builder.WriteString(", ") + builder.WriteString("box_sn_list=") + builder.WriteString(_m.BoxSnList) + builder.WriteString(", ") + builder.WriteString("contract_no=") + builder.WriteString(_m.ContractNo) + builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(fmt.Sprintf("%v", _m.CreatedAt)) builder.WriteByte(')') diff --git a/bj_power_wms/ent/outboundorder/outboundorder.go b/bj_power_wms/ent/outboundorder/outboundorder.go index 06b61f5..d21d35c 100644 --- a/bj_power_wms/ent/outboundorder/outboundorder.go +++ b/bj_power_wms/ent/outboundorder/outboundorder.go @@ -37,6 +37,12 @@ const ( FieldTargetDock = "target_dock" // FieldRemark holds the string denoting the remark field in the database. FieldRemark = "remark" + // FieldBoxNo holds the string denoting the box_no field in the database. + FieldBoxNo = "box_no" + // FieldBoxSnList holds the string denoting the box_sn_list field in the database. + FieldBoxSnList = "box_sn_list" + // FieldContractNo holds the string denoting the contract_no field in the database. + FieldContractNo = "contract_no" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" // Table holds the table name of the outboundorder in the database. @@ -59,6 +65,9 @@ var Columns = []string{ FieldReviewer, FieldTargetDock, FieldRemark, + FieldBoxNo, + FieldBoxSnList, + FieldContractNo, FieldCreatedAt, } @@ -156,6 +165,21 @@ func ByRemark(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldRemark, opts...).ToFunc() } +// ByBoxNo orders the results by the box_no field. +func ByBoxNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBoxNo, opts...).ToFunc() +} + +// ByBoxSnList orders the results by the box_sn_list field. +func ByBoxSnList(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBoxSnList, opts...).ToFunc() +} + +// ByContractNo orders the results by the contract_no field. +func ByContractNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldContractNo, opts...).ToFunc() +} + // ByCreatedAt orders the results by the created_at field. func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() diff --git a/bj_power_wms/ent/outboundorder/where.go b/bj_power_wms/ent/outboundorder/where.go index 02c3754..baf02bf 100644 --- a/bj_power_wms/ent/outboundorder/where.go +++ b/bj_power_wms/ent/outboundorder/where.go @@ -118,6 +118,21 @@ func Remark(v string) predicate.OutboundOrder { return predicate.OutboundOrder(sql.FieldEQ(FieldRemark, v)) } +// BoxNo applies equality check predicate on the "box_no" field. It's identical to BoxNoEQ. +func BoxNo(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEQ(FieldBoxNo, v)) +} + +// BoxSnList applies equality check predicate on the "box_sn_list" field. It's identical to BoxSnListEQ. +func BoxSnList(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEQ(FieldBoxSnList, v)) +} + +// ContractNo applies equality check predicate on the "contract_no" field. It's identical to ContractNoEQ. +func ContractNo(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEQ(FieldContractNo, v)) +} + // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v int64) predicate.OutboundOrder { return predicate.OutboundOrder(sql.FieldEQ(FieldCreatedAt, v)) @@ -998,6 +1013,231 @@ func RemarkContainsFold(v string) predicate.OutboundOrder { return predicate.OutboundOrder(sql.FieldContainsFold(FieldRemark, v)) } +// BoxNoEQ applies the EQ predicate on the "box_no" field. +func BoxNoEQ(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEQ(FieldBoxNo, v)) +} + +// BoxNoNEQ applies the NEQ predicate on the "box_no" field. +func BoxNoNEQ(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNEQ(FieldBoxNo, v)) +} + +// BoxNoIn applies the In predicate on the "box_no" field. +func BoxNoIn(vs ...string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldIn(FieldBoxNo, vs...)) +} + +// BoxNoNotIn applies the NotIn predicate on the "box_no" field. +func BoxNoNotIn(vs ...string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNotIn(FieldBoxNo, vs...)) +} + +// BoxNoGT applies the GT predicate on the "box_no" field. +func BoxNoGT(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldGT(FieldBoxNo, v)) +} + +// BoxNoGTE applies the GTE predicate on the "box_no" field. +func BoxNoGTE(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldGTE(FieldBoxNo, v)) +} + +// BoxNoLT applies the LT predicate on the "box_no" field. +func BoxNoLT(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldLT(FieldBoxNo, v)) +} + +// BoxNoLTE applies the LTE predicate on the "box_no" field. +func BoxNoLTE(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldLTE(FieldBoxNo, v)) +} + +// BoxNoContains applies the Contains predicate on the "box_no" field. +func BoxNoContains(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldContains(FieldBoxNo, v)) +} + +// BoxNoHasPrefix applies the HasPrefix predicate on the "box_no" field. +func BoxNoHasPrefix(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldHasPrefix(FieldBoxNo, v)) +} + +// BoxNoHasSuffix applies the HasSuffix predicate on the "box_no" field. +func BoxNoHasSuffix(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldHasSuffix(FieldBoxNo, v)) +} + +// BoxNoIsNil applies the IsNil predicate on the "box_no" field. +func BoxNoIsNil() predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldIsNull(FieldBoxNo)) +} + +// BoxNoNotNil applies the NotNil predicate on the "box_no" field. +func BoxNoNotNil() predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNotNull(FieldBoxNo)) +} + +// BoxNoEqualFold applies the EqualFold predicate on the "box_no" field. +func BoxNoEqualFold(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEqualFold(FieldBoxNo, v)) +} + +// BoxNoContainsFold applies the ContainsFold predicate on the "box_no" field. +func BoxNoContainsFold(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldContainsFold(FieldBoxNo, v)) +} + +// BoxSnListEQ applies the EQ predicate on the "box_sn_list" field. +func BoxSnListEQ(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEQ(FieldBoxSnList, v)) +} + +// BoxSnListNEQ applies the NEQ predicate on the "box_sn_list" field. +func BoxSnListNEQ(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNEQ(FieldBoxSnList, v)) +} + +// BoxSnListIn applies the In predicate on the "box_sn_list" field. +func BoxSnListIn(vs ...string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldIn(FieldBoxSnList, vs...)) +} + +// BoxSnListNotIn applies the NotIn predicate on the "box_sn_list" field. +func BoxSnListNotIn(vs ...string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNotIn(FieldBoxSnList, vs...)) +} + +// BoxSnListGT applies the GT predicate on the "box_sn_list" field. +func BoxSnListGT(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldGT(FieldBoxSnList, v)) +} + +// BoxSnListGTE applies the GTE predicate on the "box_sn_list" field. +func BoxSnListGTE(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldGTE(FieldBoxSnList, v)) +} + +// BoxSnListLT applies the LT predicate on the "box_sn_list" field. +func BoxSnListLT(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldLT(FieldBoxSnList, v)) +} + +// BoxSnListLTE applies the LTE predicate on the "box_sn_list" field. +func BoxSnListLTE(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldLTE(FieldBoxSnList, v)) +} + +// BoxSnListContains applies the Contains predicate on the "box_sn_list" field. +func BoxSnListContains(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldContains(FieldBoxSnList, v)) +} + +// BoxSnListHasPrefix applies the HasPrefix predicate on the "box_sn_list" field. +func BoxSnListHasPrefix(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldHasPrefix(FieldBoxSnList, v)) +} + +// BoxSnListHasSuffix applies the HasSuffix predicate on the "box_sn_list" field. +func BoxSnListHasSuffix(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldHasSuffix(FieldBoxSnList, v)) +} + +// BoxSnListIsNil applies the IsNil predicate on the "box_sn_list" field. +func BoxSnListIsNil() predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldIsNull(FieldBoxSnList)) +} + +// BoxSnListNotNil applies the NotNil predicate on the "box_sn_list" field. +func BoxSnListNotNil() predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNotNull(FieldBoxSnList)) +} + +// BoxSnListEqualFold applies the EqualFold predicate on the "box_sn_list" field. +func BoxSnListEqualFold(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEqualFold(FieldBoxSnList, v)) +} + +// BoxSnListContainsFold applies the ContainsFold predicate on the "box_sn_list" field. +func BoxSnListContainsFold(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldContainsFold(FieldBoxSnList, v)) +} + +// ContractNoEQ applies the EQ predicate on the "contract_no" field. +func ContractNoEQ(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEQ(FieldContractNo, v)) +} + +// ContractNoNEQ applies the NEQ predicate on the "contract_no" field. +func ContractNoNEQ(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNEQ(FieldContractNo, v)) +} + +// ContractNoIn applies the In predicate on the "contract_no" field. +func ContractNoIn(vs ...string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldIn(FieldContractNo, vs...)) +} + +// ContractNoNotIn applies the NotIn predicate on the "contract_no" field. +func ContractNoNotIn(vs ...string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNotIn(FieldContractNo, vs...)) +} + +// ContractNoGT applies the GT predicate on the "contract_no" field. +func ContractNoGT(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldGT(FieldContractNo, v)) +} + +// ContractNoGTE applies the GTE predicate on the "contract_no" field. +func ContractNoGTE(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldGTE(FieldContractNo, v)) +} + +// ContractNoLT applies the LT predicate on the "contract_no" field. +func ContractNoLT(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldLT(FieldContractNo, v)) +} + +// ContractNoLTE applies the LTE predicate on the "contract_no" field. +func ContractNoLTE(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldLTE(FieldContractNo, v)) +} + +// ContractNoContains applies the Contains predicate on the "contract_no" field. +func ContractNoContains(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldContains(FieldContractNo, v)) +} + +// ContractNoHasPrefix applies the HasPrefix predicate on the "contract_no" field. +func ContractNoHasPrefix(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldHasPrefix(FieldContractNo, v)) +} + +// ContractNoHasSuffix applies the HasSuffix predicate on the "contract_no" field. +func ContractNoHasSuffix(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldHasSuffix(FieldContractNo, v)) +} + +// ContractNoIsNil applies the IsNil predicate on the "contract_no" field. +func ContractNoIsNil() predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldIsNull(FieldContractNo)) +} + +// ContractNoNotNil applies the NotNil predicate on the "contract_no" field. +func ContractNoNotNil() predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldNotNull(FieldContractNo)) +} + +// ContractNoEqualFold applies the EqualFold predicate on the "contract_no" field. +func ContractNoEqualFold(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldEqualFold(FieldContractNo, v)) +} + +// ContractNoContainsFold applies the ContainsFold predicate on the "contract_no" field. +func ContractNoContainsFold(v string) predicate.OutboundOrder { + return predicate.OutboundOrder(sql.FieldContainsFold(FieldContractNo, v)) +} + // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v int64) predicate.OutboundOrder { return predicate.OutboundOrder(sql.FieldEQ(FieldCreatedAt, v)) diff --git a/bj_power_wms/ent/outboundorder_create.go b/bj_power_wms/ent/outboundorder_create.go index a0b7e13..5a31685 100644 --- a/bj_power_wms/ent/outboundorder_create.go +++ b/bj_power_wms/ent/outboundorder_create.go @@ -187,6 +187,48 @@ func (_c *OutboundOrderCreate) SetNillableRemark(v *string) *OutboundOrderCreate return _c } +// SetBoxNo sets the "box_no" field. +func (_c *OutboundOrderCreate) SetBoxNo(v string) *OutboundOrderCreate { + _c.mutation.SetBoxNo(v) + return _c +} + +// SetNillableBoxNo sets the "box_no" field if the given value is not nil. +func (_c *OutboundOrderCreate) SetNillableBoxNo(v *string) *OutboundOrderCreate { + if v != nil { + _c.SetBoxNo(*v) + } + return _c +} + +// SetBoxSnList sets the "box_sn_list" field. +func (_c *OutboundOrderCreate) SetBoxSnList(v string) *OutboundOrderCreate { + _c.mutation.SetBoxSnList(v) + return _c +} + +// SetNillableBoxSnList sets the "box_sn_list" field if the given value is not nil. +func (_c *OutboundOrderCreate) SetNillableBoxSnList(v *string) *OutboundOrderCreate { + if v != nil { + _c.SetBoxSnList(*v) + } + return _c +} + +// SetContractNo sets the "contract_no" field. +func (_c *OutboundOrderCreate) SetContractNo(v string) *OutboundOrderCreate { + _c.mutation.SetContractNo(v) + return _c +} + +// SetNillableContractNo sets the "contract_no" field if the given value is not nil. +func (_c *OutboundOrderCreate) SetNillableContractNo(v *string) *OutboundOrderCreate { + if v != nil { + _c.SetContractNo(*v) + } + return _c +} + // SetCreatedAt sets the "created_at" field. func (_c *OutboundOrderCreate) SetCreatedAt(v int64) *OutboundOrderCreate { _c.mutation.SetCreatedAt(v) @@ -353,6 +395,18 @@ func (_c *OutboundOrderCreate) createSpec() (*OutboundOrder, *sqlgraph.CreateSpe _spec.SetField(outboundorder.FieldRemark, field.TypeString, value) _node.Remark = value } + if value, ok := _c.mutation.BoxNo(); ok { + _spec.SetField(outboundorder.FieldBoxNo, field.TypeString, value) + _node.BoxNo = value + } + if value, ok := _c.mutation.BoxSnList(); ok { + _spec.SetField(outboundorder.FieldBoxSnList, field.TypeString, value) + _node.BoxSnList = value + } + if value, ok := _c.mutation.ContractNo(); ok { + _spec.SetField(outboundorder.FieldContractNo, field.TypeString, value) + _node.ContractNo = value + } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(outboundorder.FieldCreatedAt, field.TypeInt64, value) _node.CreatedAt = value @@ -625,6 +679,60 @@ func (u *OutboundOrderUpsert) ClearRemark() *OutboundOrderUpsert { return u } +// SetBoxNo sets the "box_no" field. +func (u *OutboundOrderUpsert) SetBoxNo(v string) *OutboundOrderUpsert { + u.Set(outboundorder.FieldBoxNo, v) + return u +} + +// UpdateBoxNo sets the "box_no" field to the value that was provided on create. +func (u *OutboundOrderUpsert) UpdateBoxNo() *OutboundOrderUpsert { + u.SetExcluded(outboundorder.FieldBoxNo) + return u +} + +// ClearBoxNo clears the value of the "box_no" field. +func (u *OutboundOrderUpsert) ClearBoxNo() *OutboundOrderUpsert { + u.SetNull(outboundorder.FieldBoxNo) + return u +} + +// SetBoxSnList sets the "box_sn_list" field. +func (u *OutboundOrderUpsert) SetBoxSnList(v string) *OutboundOrderUpsert { + u.Set(outboundorder.FieldBoxSnList, v) + return u +} + +// UpdateBoxSnList sets the "box_sn_list" field to the value that was provided on create. +func (u *OutboundOrderUpsert) UpdateBoxSnList() *OutboundOrderUpsert { + u.SetExcluded(outboundorder.FieldBoxSnList) + return u +} + +// ClearBoxSnList clears the value of the "box_sn_list" field. +func (u *OutboundOrderUpsert) ClearBoxSnList() *OutboundOrderUpsert { + u.SetNull(outboundorder.FieldBoxSnList) + return u +} + +// SetContractNo sets the "contract_no" field. +func (u *OutboundOrderUpsert) SetContractNo(v string) *OutboundOrderUpsert { + u.Set(outboundorder.FieldContractNo, v) + return u +} + +// UpdateContractNo sets the "contract_no" field to the value that was provided on create. +func (u *OutboundOrderUpsert) UpdateContractNo() *OutboundOrderUpsert { + u.SetExcluded(outboundorder.FieldContractNo) + return u +} + +// ClearContractNo clears the value of the "contract_no" field. +func (u *OutboundOrderUpsert) ClearContractNo() *OutboundOrderUpsert { + u.SetNull(outboundorder.FieldContractNo) + return u +} + // SetCreatedAt sets the "created_at" field. func (u *OutboundOrderUpsert) SetCreatedAt(v int64) *OutboundOrderUpsert { u.Set(outboundorder.FieldCreatedAt, v) @@ -935,6 +1043,69 @@ func (u *OutboundOrderUpsertOne) ClearRemark() *OutboundOrderUpsertOne { }) } +// SetBoxNo sets the "box_no" field. +func (u *OutboundOrderUpsertOne) SetBoxNo(v string) *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.SetBoxNo(v) + }) +} + +// UpdateBoxNo sets the "box_no" field to the value that was provided on create. +func (u *OutboundOrderUpsertOne) UpdateBoxNo() *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.UpdateBoxNo() + }) +} + +// ClearBoxNo clears the value of the "box_no" field. +func (u *OutboundOrderUpsertOne) ClearBoxNo() *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.ClearBoxNo() + }) +} + +// SetBoxSnList sets the "box_sn_list" field. +func (u *OutboundOrderUpsertOne) SetBoxSnList(v string) *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.SetBoxSnList(v) + }) +} + +// UpdateBoxSnList sets the "box_sn_list" field to the value that was provided on create. +func (u *OutboundOrderUpsertOne) UpdateBoxSnList() *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.UpdateBoxSnList() + }) +} + +// ClearBoxSnList clears the value of the "box_sn_list" field. +func (u *OutboundOrderUpsertOne) ClearBoxSnList() *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.ClearBoxSnList() + }) +} + +// SetContractNo sets the "contract_no" field. +func (u *OutboundOrderUpsertOne) SetContractNo(v string) *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.SetContractNo(v) + }) +} + +// UpdateContractNo sets the "contract_no" field to the value that was provided on create. +func (u *OutboundOrderUpsertOne) UpdateContractNo() *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.UpdateContractNo() + }) +} + +// ClearContractNo clears the value of the "contract_no" field. +func (u *OutboundOrderUpsertOne) ClearContractNo() *OutboundOrderUpsertOne { + return u.Update(func(s *OutboundOrderUpsert) { + s.ClearContractNo() + }) +} + // SetCreatedAt sets the "created_at" field. func (u *OutboundOrderUpsertOne) SetCreatedAt(v int64) *OutboundOrderUpsertOne { return u.Update(func(s *OutboundOrderUpsert) { @@ -1412,6 +1583,69 @@ func (u *OutboundOrderUpsertBulk) ClearRemark() *OutboundOrderUpsertBulk { }) } +// SetBoxNo sets the "box_no" field. +func (u *OutboundOrderUpsertBulk) SetBoxNo(v string) *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.SetBoxNo(v) + }) +} + +// UpdateBoxNo sets the "box_no" field to the value that was provided on create. +func (u *OutboundOrderUpsertBulk) UpdateBoxNo() *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.UpdateBoxNo() + }) +} + +// ClearBoxNo clears the value of the "box_no" field. +func (u *OutboundOrderUpsertBulk) ClearBoxNo() *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.ClearBoxNo() + }) +} + +// SetBoxSnList sets the "box_sn_list" field. +func (u *OutboundOrderUpsertBulk) SetBoxSnList(v string) *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.SetBoxSnList(v) + }) +} + +// UpdateBoxSnList sets the "box_sn_list" field to the value that was provided on create. +func (u *OutboundOrderUpsertBulk) UpdateBoxSnList() *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.UpdateBoxSnList() + }) +} + +// ClearBoxSnList clears the value of the "box_sn_list" field. +func (u *OutboundOrderUpsertBulk) ClearBoxSnList() *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.ClearBoxSnList() + }) +} + +// SetContractNo sets the "contract_no" field. +func (u *OutboundOrderUpsertBulk) SetContractNo(v string) *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.SetContractNo(v) + }) +} + +// UpdateContractNo sets the "contract_no" field to the value that was provided on create. +func (u *OutboundOrderUpsertBulk) UpdateContractNo() *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.UpdateContractNo() + }) +} + +// ClearContractNo clears the value of the "contract_no" field. +func (u *OutboundOrderUpsertBulk) ClearContractNo() *OutboundOrderUpsertBulk { + return u.Update(func(s *OutboundOrderUpsert) { + s.ClearContractNo() + }) +} + // SetCreatedAt sets the "created_at" field. func (u *OutboundOrderUpsertBulk) SetCreatedAt(v int64) *OutboundOrderUpsertBulk { return u.Update(func(s *OutboundOrderUpsert) { diff --git a/bj_power_wms/ent/outboundorder_update.go b/bj_power_wms/ent/outboundorder_update.go index 8243f06..c9b31b9 100644 --- a/bj_power_wms/ent/outboundorder_update.go +++ b/bj_power_wms/ent/outboundorder_update.go @@ -271,6 +271,66 @@ func (_u *OutboundOrderUpdate) ClearRemark() *OutboundOrderUpdate { return _u } +// SetBoxNo sets the "box_no" field. +func (_u *OutboundOrderUpdate) SetBoxNo(v string) *OutboundOrderUpdate { + _u.mutation.SetBoxNo(v) + return _u +} + +// SetNillableBoxNo sets the "box_no" field if the given value is not nil. +func (_u *OutboundOrderUpdate) SetNillableBoxNo(v *string) *OutboundOrderUpdate { + if v != nil { + _u.SetBoxNo(*v) + } + return _u +} + +// ClearBoxNo clears the value of the "box_no" field. +func (_u *OutboundOrderUpdate) ClearBoxNo() *OutboundOrderUpdate { + _u.mutation.ClearBoxNo() + return _u +} + +// SetBoxSnList sets the "box_sn_list" field. +func (_u *OutboundOrderUpdate) SetBoxSnList(v string) *OutboundOrderUpdate { + _u.mutation.SetBoxSnList(v) + return _u +} + +// SetNillableBoxSnList sets the "box_sn_list" field if the given value is not nil. +func (_u *OutboundOrderUpdate) SetNillableBoxSnList(v *string) *OutboundOrderUpdate { + if v != nil { + _u.SetBoxSnList(*v) + } + return _u +} + +// ClearBoxSnList clears the value of the "box_sn_list" field. +func (_u *OutboundOrderUpdate) ClearBoxSnList() *OutboundOrderUpdate { + _u.mutation.ClearBoxSnList() + return _u +} + +// SetContractNo sets the "contract_no" field. +func (_u *OutboundOrderUpdate) SetContractNo(v string) *OutboundOrderUpdate { + _u.mutation.SetContractNo(v) + return _u +} + +// SetNillableContractNo sets the "contract_no" field if the given value is not nil. +func (_u *OutboundOrderUpdate) SetNillableContractNo(v *string) *OutboundOrderUpdate { + if v != nil { + _u.SetContractNo(*v) + } + return _u +} + +// ClearContractNo clears the value of the "contract_no" field. +func (_u *OutboundOrderUpdate) ClearContractNo() *OutboundOrderUpdate { + _u.mutation.ClearContractNo() + return _u +} + // SetCreatedAt sets the "created_at" field. func (_u *OutboundOrderUpdate) SetCreatedAt(v int64) *OutboundOrderUpdate { _u.mutation.ResetCreatedAt() @@ -402,6 +462,24 @@ func (_u *OutboundOrderUpdate) sqlSave(ctx context.Context) (_node int, err erro if _u.mutation.RemarkCleared() { _spec.ClearField(outboundorder.FieldRemark, field.TypeString) } + if value, ok := _u.mutation.BoxNo(); ok { + _spec.SetField(outboundorder.FieldBoxNo, field.TypeString, value) + } + if _u.mutation.BoxNoCleared() { + _spec.ClearField(outboundorder.FieldBoxNo, field.TypeString) + } + if value, ok := _u.mutation.BoxSnList(); ok { + _spec.SetField(outboundorder.FieldBoxSnList, field.TypeString, value) + } + if _u.mutation.BoxSnListCleared() { + _spec.ClearField(outboundorder.FieldBoxSnList, field.TypeString) + } + if value, ok := _u.mutation.ContractNo(); ok { + _spec.SetField(outboundorder.FieldContractNo, field.TypeString, value) + } + if _u.mutation.ContractNoCleared() { + _spec.ClearField(outboundorder.FieldContractNo, field.TypeString) + } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(outboundorder.FieldCreatedAt, field.TypeInt64, value) } @@ -672,6 +750,66 @@ func (_u *OutboundOrderUpdateOne) ClearRemark() *OutboundOrderUpdateOne { return _u } +// SetBoxNo sets the "box_no" field. +func (_u *OutboundOrderUpdateOne) SetBoxNo(v string) *OutboundOrderUpdateOne { + _u.mutation.SetBoxNo(v) + return _u +} + +// SetNillableBoxNo sets the "box_no" field if the given value is not nil. +func (_u *OutboundOrderUpdateOne) SetNillableBoxNo(v *string) *OutboundOrderUpdateOne { + if v != nil { + _u.SetBoxNo(*v) + } + return _u +} + +// ClearBoxNo clears the value of the "box_no" field. +func (_u *OutboundOrderUpdateOne) ClearBoxNo() *OutboundOrderUpdateOne { + _u.mutation.ClearBoxNo() + return _u +} + +// SetBoxSnList sets the "box_sn_list" field. +func (_u *OutboundOrderUpdateOne) SetBoxSnList(v string) *OutboundOrderUpdateOne { + _u.mutation.SetBoxSnList(v) + return _u +} + +// SetNillableBoxSnList sets the "box_sn_list" field if the given value is not nil. +func (_u *OutboundOrderUpdateOne) SetNillableBoxSnList(v *string) *OutboundOrderUpdateOne { + if v != nil { + _u.SetBoxSnList(*v) + } + return _u +} + +// ClearBoxSnList clears the value of the "box_sn_list" field. +func (_u *OutboundOrderUpdateOne) ClearBoxSnList() *OutboundOrderUpdateOne { + _u.mutation.ClearBoxSnList() + return _u +} + +// SetContractNo sets the "contract_no" field. +func (_u *OutboundOrderUpdateOne) SetContractNo(v string) *OutboundOrderUpdateOne { + _u.mutation.SetContractNo(v) + return _u +} + +// SetNillableContractNo sets the "contract_no" field if the given value is not nil. +func (_u *OutboundOrderUpdateOne) SetNillableContractNo(v *string) *OutboundOrderUpdateOne { + if v != nil { + _u.SetContractNo(*v) + } + return _u +} + +// ClearContractNo clears the value of the "contract_no" field. +func (_u *OutboundOrderUpdateOne) ClearContractNo() *OutboundOrderUpdateOne { + _u.mutation.ClearContractNo() + return _u +} + // SetCreatedAt sets the "created_at" field. func (_u *OutboundOrderUpdateOne) SetCreatedAt(v int64) *OutboundOrderUpdateOne { _u.mutation.ResetCreatedAt() @@ -833,6 +971,24 @@ func (_u *OutboundOrderUpdateOne) sqlSave(ctx context.Context) (_node *OutboundO if _u.mutation.RemarkCleared() { _spec.ClearField(outboundorder.FieldRemark, field.TypeString) } + if value, ok := _u.mutation.BoxNo(); ok { + _spec.SetField(outboundorder.FieldBoxNo, field.TypeString, value) + } + if _u.mutation.BoxNoCleared() { + _spec.ClearField(outboundorder.FieldBoxNo, field.TypeString) + } + if value, ok := _u.mutation.BoxSnList(); ok { + _spec.SetField(outboundorder.FieldBoxSnList, field.TypeString, value) + } + if _u.mutation.BoxSnListCleared() { + _spec.ClearField(outboundorder.FieldBoxSnList, field.TypeString) + } + if value, ok := _u.mutation.ContractNo(); ok { + _spec.SetField(outboundorder.FieldContractNo, field.TypeString, value) + } + if _u.mutation.ContractNoCleared() { + _spec.ClearField(outboundorder.FieldContractNo, field.TypeString) + } if value, ok := _u.mutation.CreatedAt(); ok { _spec.SetField(outboundorder.FieldCreatedAt, field.TypeInt64, value) } diff --git a/bj_power_wms/ent/packagebox/packagebox.go b/bj_power_wms/ent/packagebox/packagebox.go deleted file mode 100644 index 7743d54..0000000 --- a/bj_power_wms/ent/packagebox/packagebox.go +++ /dev/null @@ -1,120 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package packagebox - -import ( - "entgo.io/ent/dialect/sql" -) - -const ( - // Label holds the string label denoting the packagebox type in the database. - Label = "package_box" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldBoxNo holds the string denoting the box_no field in the database. - FieldBoxNo = "box_no" - // FieldSnList holds the string denoting the sn_list field in the database. - FieldSnList = "sn_list" - // FieldMaterialCode holds the string denoting the material_code field in the database. - FieldMaterialCode = "material_code" - // FieldQuantity holds the string denoting the quantity field in the database. - FieldQuantity = "quantity" - // FieldOperator holds the string denoting the operator field in the database. - FieldOperator = "operator" - // FieldContractNo holds the string denoting the contract_no field in the database. - FieldContractNo = "contract_no" - // FieldRemark holds the string denoting the remark field in the database. - FieldRemark = "remark" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - // Table holds the table name of the packagebox in the database. - Table = "package_boxes" -) - -// Columns holds all SQL columns for packagebox fields. -var Columns = []string{ - FieldID, - FieldBoxNo, - FieldSnList, - FieldMaterialCode, - FieldQuantity, - FieldOperator, - FieldContractNo, - FieldRemark, - FieldCreatedAt, - FieldUpdatedAt, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultQuantity holds the default value on creation for the "quantity" field. - DefaultQuantity int - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() int64 - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() int64 -) - -// OrderOption defines the ordering options for the PackageBox queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByBoxNo orders the results by the box_no field. -func ByBoxNo(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldBoxNo, opts...).ToFunc() -} - -// BySnList orders the results by the sn_list field. -func BySnList(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldSnList, opts...).ToFunc() -} - -// ByMaterialCode orders the results by the material_code field. -func ByMaterialCode(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldMaterialCode, opts...).ToFunc() -} - -// ByQuantity orders the results by the quantity field. -func ByQuantity(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldQuantity, opts...).ToFunc() -} - -// ByOperator orders the results by the operator field. -func ByOperator(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldOperator, opts...).ToFunc() -} - -// ByContractNo orders the results by the contract_no field. -func ByContractNo(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldContractNo, opts...).ToFunc() -} - -// ByRemark orders the results by the remark field. -func ByRemark(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldRemark, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByUpdatedAt orders the results by the updated_at field. -func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() -} diff --git a/bj_power_wms/ent/packagebox/where.go b/bj_power_wms/ent/packagebox/where.go deleted file mode 100644 index 81f6e1c..0000000 --- a/bj_power_wms/ent/packagebox/where.go +++ /dev/null @@ -1,684 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package packagebox - -import ( - "bj_power_wms/ent/predicate" - - "entgo.io/ent/dialect/sql" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldID, id)) -} - -// BoxNo applies equality check predicate on the "box_no" field. It's identical to BoxNoEQ. -func BoxNo(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldBoxNo, v)) -} - -// SnList applies equality check predicate on the "sn_list" field. It's identical to SnListEQ. -func SnList(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldSnList, v)) -} - -// MaterialCode applies equality check predicate on the "material_code" field. It's identical to MaterialCodeEQ. -func MaterialCode(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldMaterialCode, v)) -} - -// Quantity applies equality check predicate on the "quantity" field. It's identical to QuantityEQ. -func Quantity(v int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldQuantity, v)) -} - -// Operator applies equality check predicate on the "operator" field. It's identical to OperatorEQ. -func Operator(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldOperator, v)) -} - -// ContractNo applies equality check predicate on the "contract_no" field. It's identical to ContractNoEQ. -func ContractNo(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldContractNo, v)) -} - -// Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. -func Remark(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldRemark, v)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldCreatedAt, v)) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// BoxNoEQ applies the EQ predicate on the "box_no" field. -func BoxNoEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldBoxNo, v)) -} - -// BoxNoNEQ applies the NEQ predicate on the "box_no" field. -func BoxNoNEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldBoxNo, v)) -} - -// BoxNoIn applies the In predicate on the "box_no" field. -func BoxNoIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldBoxNo, vs...)) -} - -// BoxNoNotIn applies the NotIn predicate on the "box_no" field. -func BoxNoNotIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldBoxNo, vs...)) -} - -// BoxNoGT applies the GT predicate on the "box_no" field. -func BoxNoGT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldBoxNo, v)) -} - -// BoxNoGTE applies the GTE predicate on the "box_no" field. -func BoxNoGTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldBoxNo, v)) -} - -// BoxNoLT applies the LT predicate on the "box_no" field. -func BoxNoLT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldBoxNo, v)) -} - -// BoxNoLTE applies the LTE predicate on the "box_no" field. -func BoxNoLTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldBoxNo, v)) -} - -// BoxNoContains applies the Contains predicate on the "box_no" field. -func BoxNoContains(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContains(FieldBoxNo, v)) -} - -// BoxNoHasPrefix applies the HasPrefix predicate on the "box_no" field. -func BoxNoHasPrefix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasPrefix(FieldBoxNo, v)) -} - -// BoxNoHasSuffix applies the HasSuffix predicate on the "box_no" field. -func BoxNoHasSuffix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasSuffix(FieldBoxNo, v)) -} - -// BoxNoEqualFold applies the EqualFold predicate on the "box_no" field. -func BoxNoEqualFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEqualFold(FieldBoxNo, v)) -} - -// BoxNoContainsFold applies the ContainsFold predicate on the "box_no" field. -func BoxNoContainsFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContainsFold(FieldBoxNo, v)) -} - -// SnListEQ applies the EQ predicate on the "sn_list" field. -func SnListEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldSnList, v)) -} - -// SnListNEQ applies the NEQ predicate on the "sn_list" field. -func SnListNEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldSnList, v)) -} - -// SnListIn applies the In predicate on the "sn_list" field. -func SnListIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldSnList, vs...)) -} - -// SnListNotIn applies the NotIn predicate on the "sn_list" field. -func SnListNotIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldSnList, vs...)) -} - -// SnListGT applies the GT predicate on the "sn_list" field. -func SnListGT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldSnList, v)) -} - -// SnListGTE applies the GTE predicate on the "sn_list" field. -func SnListGTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldSnList, v)) -} - -// SnListLT applies the LT predicate on the "sn_list" field. -func SnListLT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldSnList, v)) -} - -// SnListLTE applies the LTE predicate on the "sn_list" field. -func SnListLTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldSnList, v)) -} - -// SnListContains applies the Contains predicate on the "sn_list" field. -func SnListContains(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContains(FieldSnList, v)) -} - -// SnListHasPrefix applies the HasPrefix predicate on the "sn_list" field. -func SnListHasPrefix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasPrefix(FieldSnList, v)) -} - -// SnListHasSuffix applies the HasSuffix predicate on the "sn_list" field. -func SnListHasSuffix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasSuffix(FieldSnList, v)) -} - -// SnListIsNil applies the IsNil predicate on the "sn_list" field. -func SnListIsNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldIsNull(FieldSnList)) -} - -// SnListNotNil applies the NotNil predicate on the "sn_list" field. -func SnListNotNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotNull(FieldSnList)) -} - -// SnListEqualFold applies the EqualFold predicate on the "sn_list" field. -func SnListEqualFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEqualFold(FieldSnList, v)) -} - -// SnListContainsFold applies the ContainsFold predicate on the "sn_list" field. -func SnListContainsFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContainsFold(FieldSnList, v)) -} - -// MaterialCodeEQ applies the EQ predicate on the "material_code" field. -func MaterialCodeEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldMaterialCode, v)) -} - -// MaterialCodeNEQ applies the NEQ predicate on the "material_code" field. -func MaterialCodeNEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldMaterialCode, v)) -} - -// MaterialCodeIn applies the In predicate on the "material_code" field. -func MaterialCodeIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldMaterialCode, vs...)) -} - -// MaterialCodeNotIn applies the NotIn predicate on the "material_code" field. -func MaterialCodeNotIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldMaterialCode, vs...)) -} - -// MaterialCodeGT applies the GT predicate on the "material_code" field. -func MaterialCodeGT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldMaterialCode, v)) -} - -// MaterialCodeGTE applies the GTE predicate on the "material_code" field. -func MaterialCodeGTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldMaterialCode, v)) -} - -// MaterialCodeLT applies the LT predicate on the "material_code" field. -func MaterialCodeLT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldMaterialCode, v)) -} - -// MaterialCodeLTE applies the LTE predicate on the "material_code" field. -func MaterialCodeLTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldMaterialCode, v)) -} - -// MaterialCodeContains applies the Contains predicate on the "material_code" field. -func MaterialCodeContains(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContains(FieldMaterialCode, v)) -} - -// MaterialCodeHasPrefix applies the HasPrefix predicate on the "material_code" field. -func MaterialCodeHasPrefix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasPrefix(FieldMaterialCode, v)) -} - -// MaterialCodeHasSuffix applies the HasSuffix predicate on the "material_code" field. -func MaterialCodeHasSuffix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasSuffix(FieldMaterialCode, v)) -} - -// MaterialCodeIsNil applies the IsNil predicate on the "material_code" field. -func MaterialCodeIsNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldIsNull(FieldMaterialCode)) -} - -// MaterialCodeNotNil applies the NotNil predicate on the "material_code" field. -func MaterialCodeNotNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotNull(FieldMaterialCode)) -} - -// MaterialCodeEqualFold applies the EqualFold predicate on the "material_code" field. -func MaterialCodeEqualFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEqualFold(FieldMaterialCode, v)) -} - -// MaterialCodeContainsFold applies the ContainsFold predicate on the "material_code" field. -func MaterialCodeContainsFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContainsFold(FieldMaterialCode, v)) -} - -// QuantityEQ applies the EQ predicate on the "quantity" field. -func QuantityEQ(v int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldQuantity, v)) -} - -// QuantityNEQ applies the NEQ predicate on the "quantity" field. -func QuantityNEQ(v int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldQuantity, v)) -} - -// QuantityIn applies the In predicate on the "quantity" field. -func QuantityIn(vs ...int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldQuantity, vs...)) -} - -// QuantityNotIn applies the NotIn predicate on the "quantity" field. -func QuantityNotIn(vs ...int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldQuantity, vs...)) -} - -// QuantityGT applies the GT predicate on the "quantity" field. -func QuantityGT(v int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldQuantity, v)) -} - -// QuantityGTE applies the GTE predicate on the "quantity" field. -func QuantityGTE(v int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldQuantity, v)) -} - -// QuantityLT applies the LT predicate on the "quantity" field. -func QuantityLT(v int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldQuantity, v)) -} - -// QuantityLTE applies the LTE predicate on the "quantity" field. -func QuantityLTE(v int) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldQuantity, v)) -} - -// OperatorEQ applies the EQ predicate on the "operator" field. -func OperatorEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldOperator, v)) -} - -// OperatorNEQ applies the NEQ predicate on the "operator" field. -func OperatorNEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldOperator, v)) -} - -// OperatorIn applies the In predicate on the "operator" field. -func OperatorIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldOperator, vs...)) -} - -// OperatorNotIn applies the NotIn predicate on the "operator" field. -func OperatorNotIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldOperator, vs...)) -} - -// OperatorGT applies the GT predicate on the "operator" field. -func OperatorGT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldOperator, v)) -} - -// OperatorGTE applies the GTE predicate on the "operator" field. -func OperatorGTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldOperator, v)) -} - -// OperatorLT applies the LT predicate on the "operator" field. -func OperatorLT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldOperator, v)) -} - -// OperatorLTE applies the LTE predicate on the "operator" field. -func OperatorLTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldOperator, v)) -} - -// OperatorContains applies the Contains predicate on the "operator" field. -func OperatorContains(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContains(FieldOperator, v)) -} - -// OperatorHasPrefix applies the HasPrefix predicate on the "operator" field. -func OperatorHasPrefix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasPrefix(FieldOperator, v)) -} - -// OperatorHasSuffix applies the HasSuffix predicate on the "operator" field. -func OperatorHasSuffix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasSuffix(FieldOperator, v)) -} - -// OperatorIsNil applies the IsNil predicate on the "operator" field. -func OperatorIsNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldIsNull(FieldOperator)) -} - -// OperatorNotNil applies the NotNil predicate on the "operator" field. -func OperatorNotNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotNull(FieldOperator)) -} - -// OperatorEqualFold applies the EqualFold predicate on the "operator" field. -func OperatorEqualFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEqualFold(FieldOperator, v)) -} - -// OperatorContainsFold applies the ContainsFold predicate on the "operator" field. -func OperatorContainsFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContainsFold(FieldOperator, v)) -} - -// ContractNoEQ applies the EQ predicate on the "contract_no" field. -func ContractNoEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldContractNo, v)) -} - -// ContractNoNEQ applies the NEQ predicate on the "contract_no" field. -func ContractNoNEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldContractNo, v)) -} - -// ContractNoIn applies the In predicate on the "contract_no" field. -func ContractNoIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldContractNo, vs...)) -} - -// ContractNoNotIn applies the NotIn predicate on the "contract_no" field. -func ContractNoNotIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldContractNo, vs...)) -} - -// ContractNoGT applies the GT predicate on the "contract_no" field. -func ContractNoGT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldContractNo, v)) -} - -// ContractNoGTE applies the GTE predicate on the "contract_no" field. -func ContractNoGTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldContractNo, v)) -} - -// ContractNoLT applies the LT predicate on the "contract_no" field. -func ContractNoLT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldContractNo, v)) -} - -// ContractNoLTE applies the LTE predicate on the "contract_no" field. -func ContractNoLTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldContractNo, v)) -} - -// ContractNoContains applies the Contains predicate on the "contract_no" field. -func ContractNoContains(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContains(FieldContractNo, v)) -} - -// ContractNoHasPrefix applies the HasPrefix predicate on the "contract_no" field. -func ContractNoHasPrefix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasPrefix(FieldContractNo, v)) -} - -// ContractNoHasSuffix applies the HasSuffix predicate on the "contract_no" field. -func ContractNoHasSuffix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasSuffix(FieldContractNo, v)) -} - -// ContractNoIsNil applies the IsNil predicate on the "contract_no" field. -func ContractNoIsNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldIsNull(FieldContractNo)) -} - -// ContractNoNotNil applies the NotNil predicate on the "contract_no" field. -func ContractNoNotNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotNull(FieldContractNo)) -} - -// ContractNoEqualFold applies the EqualFold predicate on the "contract_no" field. -func ContractNoEqualFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEqualFold(FieldContractNo, v)) -} - -// ContractNoContainsFold applies the ContainsFold predicate on the "contract_no" field. -func ContractNoContainsFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContainsFold(FieldContractNo, v)) -} - -// RemarkEQ applies the EQ predicate on the "remark" field. -func RemarkEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldRemark, v)) -} - -// RemarkNEQ applies the NEQ predicate on the "remark" field. -func RemarkNEQ(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldRemark, v)) -} - -// RemarkIn applies the In predicate on the "remark" field. -func RemarkIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldRemark, vs...)) -} - -// RemarkNotIn applies the NotIn predicate on the "remark" field. -func RemarkNotIn(vs ...string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldRemark, vs...)) -} - -// RemarkGT applies the GT predicate on the "remark" field. -func RemarkGT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldRemark, v)) -} - -// RemarkGTE applies the GTE predicate on the "remark" field. -func RemarkGTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldRemark, v)) -} - -// RemarkLT applies the LT predicate on the "remark" field. -func RemarkLT(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldRemark, v)) -} - -// RemarkLTE applies the LTE predicate on the "remark" field. -func RemarkLTE(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldRemark, v)) -} - -// RemarkContains applies the Contains predicate on the "remark" field. -func RemarkContains(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContains(FieldRemark, v)) -} - -// RemarkHasPrefix applies the HasPrefix predicate on the "remark" field. -func RemarkHasPrefix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasPrefix(FieldRemark, v)) -} - -// RemarkHasSuffix applies the HasSuffix predicate on the "remark" field. -func RemarkHasSuffix(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldHasSuffix(FieldRemark, v)) -} - -// RemarkIsNil applies the IsNil predicate on the "remark" field. -func RemarkIsNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldIsNull(FieldRemark)) -} - -// RemarkNotNil applies the NotNil predicate on the "remark" field. -func RemarkNotNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotNull(FieldRemark)) -} - -// RemarkEqualFold applies the EqualFold predicate on the "remark" field. -func RemarkEqualFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEqualFold(FieldRemark, v)) -} - -// RemarkContainsFold applies the ContainsFold predicate on the "remark" field. -func RemarkContainsFold(v string) predicate.PackageBox { - return predicate.PackageBox(sql.FieldContainsFold(FieldRemark, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldCreatedAt, v)) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGT(FieldUpdatedAt, v)) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldGTE(FieldUpdatedAt, v)) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLT(FieldUpdatedAt, v)) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v int64) predicate.PackageBox { - return predicate.PackageBox(sql.FieldLTE(FieldUpdatedAt, v)) -} - -// UpdatedAtIsNil applies the IsNil predicate on the "updated_at" field. -func UpdatedAtIsNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldIsNull(FieldUpdatedAt)) -} - -// UpdatedAtNotNil applies the NotNil predicate on the "updated_at" field. -func UpdatedAtNotNil() predicate.PackageBox { - return predicate.PackageBox(sql.FieldNotNull(FieldUpdatedAt)) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.PackageBox) predicate.PackageBox { - return predicate.PackageBox(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.PackageBox) predicate.PackageBox { - return predicate.PackageBox(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.PackageBox) predicate.PackageBox { - return predicate.PackageBox(sql.NotPredicates(p)) -} diff --git a/bj_power_wms/ent/packagebox_create.go b/bj_power_wms/ent/packagebox_create.go deleted file mode 100644 index 7f0d686..0000000 --- a/bj_power_wms/ent/packagebox_create.go +++ /dev/null @@ -1,1122 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "bj_power_wms/ent/packagebox" - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// PackageBoxCreate is the builder for creating a PackageBox entity. -type PackageBoxCreate struct { - config - mutation *PackageBoxMutation - hooks []Hook - conflict []sql.ConflictOption -} - -// SetBoxNo sets the "box_no" field. -func (_c *PackageBoxCreate) SetBoxNo(v string) *PackageBoxCreate { - _c.mutation.SetBoxNo(v) - return _c -} - -// SetSnList sets the "sn_list" field. -func (_c *PackageBoxCreate) SetSnList(v string) *PackageBoxCreate { - _c.mutation.SetSnList(v) - return _c -} - -// SetNillableSnList sets the "sn_list" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableSnList(v *string) *PackageBoxCreate { - if v != nil { - _c.SetSnList(*v) - } - return _c -} - -// SetMaterialCode sets the "material_code" field. -func (_c *PackageBoxCreate) SetMaterialCode(v string) *PackageBoxCreate { - _c.mutation.SetMaterialCode(v) - return _c -} - -// SetNillableMaterialCode sets the "material_code" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableMaterialCode(v *string) *PackageBoxCreate { - if v != nil { - _c.SetMaterialCode(*v) - } - return _c -} - -// SetQuantity sets the "quantity" field. -func (_c *PackageBoxCreate) SetQuantity(v int) *PackageBoxCreate { - _c.mutation.SetQuantity(v) - return _c -} - -// SetNillableQuantity sets the "quantity" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableQuantity(v *int) *PackageBoxCreate { - if v != nil { - _c.SetQuantity(*v) - } - return _c -} - -// SetOperator sets the "operator" field. -func (_c *PackageBoxCreate) SetOperator(v string) *PackageBoxCreate { - _c.mutation.SetOperator(v) - return _c -} - -// SetNillableOperator sets the "operator" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableOperator(v *string) *PackageBoxCreate { - if v != nil { - _c.SetOperator(*v) - } - return _c -} - -// SetContractNo sets the "contract_no" field. -func (_c *PackageBoxCreate) SetContractNo(v string) *PackageBoxCreate { - _c.mutation.SetContractNo(v) - return _c -} - -// SetNillableContractNo sets the "contract_no" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableContractNo(v *string) *PackageBoxCreate { - if v != nil { - _c.SetContractNo(*v) - } - return _c -} - -// SetRemark sets the "remark" field. -func (_c *PackageBoxCreate) SetRemark(v string) *PackageBoxCreate { - _c.mutation.SetRemark(v) - return _c -} - -// SetNillableRemark sets the "remark" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableRemark(v *string) *PackageBoxCreate { - if v != nil { - _c.SetRemark(*v) - } - return _c -} - -// SetCreatedAt sets the "created_at" field. -func (_c *PackageBoxCreate) SetCreatedAt(v int64) *PackageBoxCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableCreatedAt(v *int64) *PackageBoxCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetUpdatedAt sets the "updated_at" field. -func (_c *PackageBoxCreate) SetUpdatedAt(v int64) *PackageBoxCreate { - _c.mutation.SetUpdatedAt(v) - return _c -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *PackageBoxCreate) SetNillableUpdatedAt(v *int64) *PackageBoxCreate { - if v != nil { - _c.SetUpdatedAt(*v) - } - return _c -} - -// Mutation returns the PackageBoxMutation object of the builder. -func (_c *PackageBoxCreate) Mutation() *PackageBoxMutation { - return _c.mutation -} - -// Save creates the PackageBox in the database. -func (_c *PackageBoxCreate) Save(ctx context.Context) (*PackageBox, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *PackageBoxCreate) SaveX(ctx context.Context) *PackageBox { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *PackageBoxCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *PackageBoxCreate) 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 *PackageBoxCreate) defaults() { - if _, ok := _c.mutation.Quantity(); !ok { - v := packagebox.DefaultQuantity - _c.mutation.SetQuantity(v) - } - if _, ok := _c.mutation.CreatedAt(); !ok { - v := packagebox.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - v := packagebox.DefaultUpdatedAt() - _c.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *PackageBoxCreate) check() error { - if _, ok := _c.mutation.BoxNo(); !ok { - return &ValidationError{Name: "box_no", err: errors.New(`ent: missing required field "PackageBox.box_no"`)} - } - if _, ok := _c.mutation.Quantity(); !ok { - return &ValidationError{Name: "quantity", err: errors.New(`ent: missing required field "PackageBox.quantity"`)} - } - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "PackageBox.created_at"`)} - } - return nil -} - -func (_c *PackageBoxCreate) sqlSave(ctx context.Context) (*PackageBox, 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 - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *PackageBoxCreate) createSpec() (*PackageBox, *sqlgraph.CreateSpec) { - var ( - _node = &PackageBox{config: _c.config} - _spec = sqlgraph.NewCreateSpec(packagebox.Table, sqlgraph.NewFieldSpec(packagebox.FieldID, field.TypeInt)) - ) - _spec.OnConflict = _c.conflict - if value, ok := _c.mutation.BoxNo(); ok { - _spec.SetField(packagebox.FieldBoxNo, field.TypeString, value) - _node.BoxNo = value - } - if value, ok := _c.mutation.SnList(); ok { - _spec.SetField(packagebox.FieldSnList, field.TypeString, value) - _node.SnList = value - } - if value, ok := _c.mutation.MaterialCode(); ok { - _spec.SetField(packagebox.FieldMaterialCode, field.TypeString, value) - _node.MaterialCode = value - } - if value, ok := _c.mutation.Quantity(); ok { - _spec.SetField(packagebox.FieldQuantity, field.TypeInt, value) - _node.Quantity = value - } - if value, ok := _c.mutation.Operator(); ok { - _spec.SetField(packagebox.FieldOperator, field.TypeString, value) - _node.Operator = value - } - if value, ok := _c.mutation.ContractNo(); ok { - _spec.SetField(packagebox.FieldContractNo, field.TypeString, value) - _node.ContractNo = value - } - if value, ok := _c.mutation.Remark(); ok { - _spec.SetField(packagebox.FieldRemark, field.TypeString, value) - _node.Remark = value - } - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(packagebox.FieldCreatedAt, field.TypeInt64, value) - _node.CreatedAt = value - } - if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(packagebox.FieldUpdatedAt, field.TypeInt64, value) - _node.UpdatedAt = value - } - return _node, _spec -} - -// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause -// of the `INSERT` statement. For example: -// -// client.PackageBox.Create(). -// SetBoxNo(v). -// OnConflict( -// // Update the row with the new values -// // the was proposed for insertion. -// sql.ResolveWithNewValues(), -// ). -// // Override some of the fields with custom -// // update values. -// Update(func(u *ent.PackageBoxUpsert) { -// SetBoxNo(v+v). -// }). -// Exec(ctx) -func (_c *PackageBoxCreate) OnConflict(opts ...sql.ConflictOption) *PackageBoxUpsertOne { - _c.conflict = opts - return &PackageBoxUpsertOne{ - create: _c, - } -} - -// OnConflictColumns calls `OnConflict` and configures the columns -// as conflict target. Using this option is equivalent to using: -// -// client.PackageBox.Create(). -// OnConflict(sql.ConflictColumns(columns...)). -// Exec(ctx) -func (_c *PackageBoxCreate) OnConflictColumns(columns ...string) *PackageBoxUpsertOne { - _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) - return &PackageBoxUpsertOne{ - create: _c, - } -} - -type ( - // PackageBoxUpsertOne is the builder for "upsert"-ing - // one PackageBox node. - PackageBoxUpsertOne struct { - create *PackageBoxCreate - } - - // PackageBoxUpsert is the "OnConflict" setter. - PackageBoxUpsert struct { - *sql.UpdateSet - } -) - -// SetBoxNo sets the "box_no" field. -func (u *PackageBoxUpsert) SetBoxNo(v string) *PackageBoxUpsert { - u.Set(packagebox.FieldBoxNo, v) - return u -} - -// UpdateBoxNo sets the "box_no" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateBoxNo() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldBoxNo) - return u -} - -// SetSnList sets the "sn_list" field. -func (u *PackageBoxUpsert) SetSnList(v string) *PackageBoxUpsert { - u.Set(packagebox.FieldSnList, v) - return u -} - -// UpdateSnList sets the "sn_list" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateSnList() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldSnList) - return u -} - -// ClearSnList clears the value of the "sn_list" field. -func (u *PackageBoxUpsert) ClearSnList() *PackageBoxUpsert { - u.SetNull(packagebox.FieldSnList) - return u -} - -// SetMaterialCode sets the "material_code" field. -func (u *PackageBoxUpsert) SetMaterialCode(v string) *PackageBoxUpsert { - u.Set(packagebox.FieldMaterialCode, v) - return u -} - -// UpdateMaterialCode sets the "material_code" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateMaterialCode() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldMaterialCode) - return u -} - -// ClearMaterialCode clears the value of the "material_code" field. -func (u *PackageBoxUpsert) ClearMaterialCode() *PackageBoxUpsert { - u.SetNull(packagebox.FieldMaterialCode) - return u -} - -// SetQuantity sets the "quantity" field. -func (u *PackageBoxUpsert) SetQuantity(v int) *PackageBoxUpsert { - u.Set(packagebox.FieldQuantity, v) - return u -} - -// UpdateQuantity sets the "quantity" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateQuantity() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldQuantity) - return u -} - -// AddQuantity adds v to the "quantity" field. -func (u *PackageBoxUpsert) AddQuantity(v int) *PackageBoxUpsert { - u.Add(packagebox.FieldQuantity, v) - return u -} - -// SetOperator sets the "operator" field. -func (u *PackageBoxUpsert) SetOperator(v string) *PackageBoxUpsert { - u.Set(packagebox.FieldOperator, v) - return u -} - -// UpdateOperator sets the "operator" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateOperator() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldOperator) - return u -} - -// ClearOperator clears the value of the "operator" field. -func (u *PackageBoxUpsert) ClearOperator() *PackageBoxUpsert { - u.SetNull(packagebox.FieldOperator) - return u -} - -// SetContractNo sets the "contract_no" field. -func (u *PackageBoxUpsert) SetContractNo(v string) *PackageBoxUpsert { - u.Set(packagebox.FieldContractNo, v) - return u -} - -// UpdateContractNo sets the "contract_no" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateContractNo() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldContractNo) - return u -} - -// ClearContractNo clears the value of the "contract_no" field. -func (u *PackageBoxUpsert) ClearContractNo() *PackageBoxUpsert { - u.SetNull(packagebox.FieldContractNo) - return u -} - -// SetRemark sets the "remark" field. -func (u *PackageBoxUpsert) SetRemark(v string) *PackageBoxUpsert { - u.Set(packagebox.FieldRemark, v) - return u -} - -// UpdateRemark sets the "remark" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateRemark() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldRemark) - return u -} - -// ClearRemark clears the value of the "remark" field. -func (u *PackageBoxUpsert) ClearRemark() *PackageBoxUpsert { - u.SetNull(packagebox.FieldRemark) - return u -} - -// SetCreatedAt sets the "created_at" field. -func (u *PackageBoxUpsert) SetCreatedAt(v int64) *PackageBoxUpsert { - u.Set(packagebox.FieldCreatedAt, v) - return u -} - -// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateCreatedAt() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldCreatedAt) - return u -} - -// AddCreatedAt adds v to the "created_at" field. -func (u *PackageBoxUpsert) AddCreatedAt(v int64) *PackageBoxUpsert { - u.Add(packagebox.FieldCreatedAt, v) - return u -} - -// SetUpdatedAt sets the "updated_at" field. -func (u *PackageBoxUpsert) SetUpdatedAt(v int64) *PackageBoxUpsert { - u.Set(packagebox.FieldUpdatedAt, v) - return u -} - -// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. -func (u *PackageBoxUpsert) UpdateUpdatedAt() *PackageBoxUpsert { - u.SetExcluded(packagebox.FieldUpdatedAt) - return u -} - -// AddUpdatedAt adds v to the "updated_at" field. -func (u *PackageBoxUpsert) AddUpdatedAt(v int64) *PackageBoxUpsert { - u.Add(packagebox.FieldUpdatedAt, v) - return u -} - -// ClearUpdatedAt clears the value of the "updated_at" field. -func (u *PackageBoxUpsert) ClearUpdatedAt() *PackageBoxUpsert { - u.SetNull(packagebox.FieldUpdatedAt) - return u -} - -// UpdateNewValues updates the mutable fields using the new values that were set on create. -// Using this option is equivalent to using: -// -// client.PackageBox.Create(). -// OnConflict( -// sql.ResolveWithNewValues(), -// ). -// Exec(ctx) -func (u *PackageBoxUpsertOne) UpdateNewValues() *PackageBoxUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) - return u -} - -// Ignore sets each column to itself in case of conflict. -// Using this option is equivalent to using: -// -// client.PackageBox.Create(). -// OnConflict(sql.ResolveWithIgnore()). -// Exec(ctx) -func (u *PackageBoxUpsertOne) Ignore() *PackageBoxUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) - return u -} - -// DoNothing configures the conflict_action to `DO NOTHING`. -// Supported only by SQLite and PostgreSQL. -func (u *PackageBoxUpsertOne) DoNothing() *PackageBoxUpsertOne { - u.create.conflict = append(u.create.conflict, sql.DoNothing()) - return u -} - -// Update allows overriding fields `UPDATE` values. See the PackageBoxCreate.OnConflict -// documentation for more info. -func (u *PackageBoxUpsertOne) Update(set func(*PackageBoxUpsert)) *PackageBoxUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { - set(&PackageBoxUpsert{UpdateSet: update}) - })) - return u -} - -// SetBoxNo sets the "box_no" field. -func (u *PackageBoxUpsertOne) SetBoxNo(v string) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetBoxNo(v) - }) -} - -// UpdateBoxNo sets the "box_no" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateBoxNo() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateBoxNo() - }) -} - -// SetSnList sets the "sn_list" field. -func (u *PackageBoxUpsertOne) SetSnList(v string) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetSnList(v) - }) -} - -// UpdateSnList sets the "sn_list" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateSnList() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateSnList() - }) -} - -// ClearSnList clears the value of the "sn_list" field. -func (u *PackageBoxUpsertOne) ClearSnList() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearSnList() - }) -} - -// SetMaterialCode sets the "material_code" field. -func (u *PackageBoxUpsertOne) SetMaterialCode(v string) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetMaterialCode(v) - }) -} - -// UpdateMaterialCode sets the "material_code" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateMaterialCode() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateMaterialCode() - }) -} - -// ClearMaterialCode clears the value of the "material_code" field. -func (u *PackageBoxUpsertOne) ClearMaterialCode() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearMaterialCode() - }) -} - -// SetQuantity sets the "quantity" field. -func (u *PackageBoxUpsertOne) SetQuantity(v int) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetQuantity(v) - }) -} - -// AddQuantity adds v to the "quantity" field. -func (u *PackageBoxUpsertOne) AddQuantity(v int) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.AddQuantity(v) - }) -} - -// UpdateQuantity sets the "quantity" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateQuantity() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateQuantity() - }) -} - -// SetOperator sets the "operator" field. -func (u *PackageBoxUpsertOne) SetOperator(v string) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetOperator(v) - }) -} - -// UpdateOperator sets the "operator" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateOperator() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateOperator() - }) -} - -// ClearOperator clears the value of the "operator" field. -func (u *PackageBoxUpsertOne) ClearOperator() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearOperator() - }) -} - -// SetContractNo sets the "contract_no" field. -func (u *PackageBoxUpsertOne) SetContractNo(v string) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetContractNo(v) - }) -} - -// UpdateContractNo sets the "contract_no" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateContractNo() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateContractNo() - }) -} - -// ClearContractNo clears the value of the "contract_no" field. -func (u *PackageBoxUpsertOne) ClearContractNo() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearContractNo() - }) -} - -// SetRemark sets the "remark" field. -func (u *PackageBoxUpsertOne) SetRemark(v string) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetRemark(v) - }) -} - -// UpdateRemark sets the "remark" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateRemark() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateRemark() - }) -} - -// ClearRemark clears the value of the "remark" field. -func (u *PackageBoxUpsertOne) ClearRemark() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearRemark() - }) -} - -// SetCreatedAt sets the "created_at" field. -func (u *PackageBoxUpsertOne) SetCreatedAt(v int64) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetCreatedAt(v) - }) -} - -// AddCreatedAt adds v to the "created_at" field. -func (u *PackageBoxUpsertOne) AddCreatedAt(v int64) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.AddCreatedAt(v) - }) -} - -// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateCreatedAt() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateCreatedAt() - }) -} - -// SetUpdatedAt sets the "updated_at" field. -func (u *PackageBoxUpsertOne) SetUpdatedAt(v int64) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.SetUpdatedAt(v) - }) -} - -// AddUpdatedAt adds v to the "updated_at" field. -func (u *PackageBoxUpsertOne) AddUpdatedAt(v int64) *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.AddUpdatedAt(v) - }) -} - -// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. -func (u *PackageBoxUpsertOne) UpdateUpdatedAt() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateUpdatedAt() - }) -} - -// ClearUpdatedAt clears the value of the "updated_at" field. -func (u *PackageBoxUpsertOne) ClearUpdatedAt() *PackageBoxUpsertOne { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearUpdatedAt() - }) -} - -// Exec executes the query. -func (u *PackageBoxUpsertOne) Exec(ctx context.Context) error { - if len(u.create.conflict) == 0 { - return errors.New("ent: missing options for PackageBoxCreate.OnConflict") - } - return u.create.Exec(ctx) -} - -// ExecX is like Exec, but panics if an error occurs. -func (u *PackageBoxUpsertOne) ExecX(ctx context.Context) { - if err := u.create.Exec(ctx); err != nil { - panic(err) - } -} - -// Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *PackageBoxUpsertOne) ID(ctx context.Context) (id int, err error) { - node, err := u.create.Save(ctx) - if err != nil { - return id, err - } - return node.ID, nil -} - -// IDX is like ID, but panics if an error occurs. -func (u *PackageBoxUpsertOne) IDX(ctx context.Context) int { - id, err := u.ID(ctx) - if err != nil { - panic(err) - } - return id -} - -// PackageBoxCreateBulk is the builder for creating many PackageBox entities in bulk. -type PackageBoxCreateBulk struct { - config - err error - builders []*PackageBoxCreate - conflict []sql.ConflictOption -} - -// Save creates the PackageBox entities in the database. -func (_c *PackageBoxCreateBulk) Save(ctx context.Context) ([]*PackageBox, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*PackageBox, 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.(*PackageBoxMutation) - 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} - spec.OnConflict = _c.conflict - // 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 { - 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 *PackageBoxCreateBulk) SaveX(ctx context.Context) []*PackageBox { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *PackageBoxCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *PackageBoxCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause -// of the `INSERT` statement. For example: -// -// client.PackageBox.CreateBulk(builders...). -// OnConflict( -// // Update the row with the new values -// // the was proposed for insertion. -// sql.ResolveWithNewValues(), -// ). -// // Override some of the fields with custom -// // update values. -// Update(func(u *ent.PackageBoxUpsert) { -// SetBoxNo(v+v). -// }). -// Exec(ctx) -func (_c *PackageBoxCreateBulk) OnConflict(opts ...sql.ConflictOption) *PackageBoxUpsertBulk { - _c.conflict = opts - return &PackageBoxUpsertBulk{ - create: _c, - } -} - -// OnConflictColumns calls `OnConflict` and configures the columns -// as conflict target. Using this option is equivalent to using: -// -// client.PackageBox.Create(). -// OnConflict(sql.ConflictColumns(columns...)). -// Exec(ctx) -func (_c *PackageBoxCreateBulk) OnConflictColumns(columns ...string) *PackageBoxUpsertBulk { - _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) - return &PackageBoxUpsertBulk{ - create: _c, - } -} - -// PackageBoxUpsertBulk is the builder for "upsert"-ing -// a bulk of PackageBox nodes. -type PackageBoxUpsertBulk struct { - create *PackageBoxCreateBulk -} - -// UpdateNewValues updates the mutable fields using the new values that -// were set on create. Using this option is equivalent to using: -// -// client.PackageBox.Create(). -// OnConflict( -// sql.ResolveWithNewValues(), -// ). -// Exec(ctx) -func (u *PackageBoxUpsertBulk) UpdateNewValues() *PackageBoxUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) - return u -} - -// Ignore sets each column to itself in case of conflict. -// Using this option is equivalent to using: -// -// client.PackageBox.Create(). -// OnConflict(sql.ResolveWithIgnore()). -// Exec(ctx) -func (u *PackageBoxUpsertBulk) Ignore() *PackageBoxUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) - return u -} - -// DoNothing configures the conflict_action to `DO NOTHING`. -// Supported only by SQLite and PostgreSQL. -func (u *PackageBoxUpsertBulk) DoNothing() *PackageBoxUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.DoNothing()) - return u -} - -// Update allows overriding fields `UPDATE` values. See the PackageBoxCreateBulk.OnConflict -// documentation for more info. -func (u *PackageBoxUpsertBulk) Update(set func(*PackageBoxUpsert)) *PackageBoxUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { - set(&PackageBoxUpsert{UpdateSet: update}) - })) - return u -} - -// SetBoxNo sets the "box_no" field. -func (u *PackageBoxUpsertBulk) SetBoxNo(v string) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetBoxNo(v) - }) -} - -// UpdateBoxNo sets the "box_no" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateBoxNo() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateBoxNo() - }) -} - -// SetSnList sets the "sn_list" field. -func (u *PackageBoxUpsertBulk) SetSnList(v string) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetSnList(v) - }) -} - -// UpdateSnList sets the "sn_list" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateSnList() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateSnList() - }) -} - -// ClearSnList clears the value of the "sn_list" field. -func (u *PackageBoxUpsertBulk) ClearSnList() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearSnList() - }) -} - -// SetMaterialCode sets the "material_code" field. -func (u *PackageBoxUpsertBulk) SetMaterialCode(v string) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetMaterialCode(v) - }) -} - -// UpdateMaterialCode sets the "material_code" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateMaterialCode() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateMaterialCode() - }) -} - -// ClearMaterialCode clears the value of the "material_code" field. -func (u *PackageBoxUpsertBulk) ClearMaterialCode() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearMaterialCode() - }) -} - -// SetQuantity sets the "quantity" field. -func (u *PackageBoxUpsertBulk) SetQuantity(v int) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetQuantity(v) - }) -} - -// AddQuantity adds v to the "quantity" field. -func (u *PackageBoxUpsertBulk) AddQuantity(v int) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.AddQuantity(v) - }) -} - -// UpdateQuantity sets the "quantity" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateQuantity() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateQuantity() - }) -} - -// SetOperator sets the "operator" field. -func (u *PackageBoxUpsertBulk) SetOperator(v string) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetOperator(v) - }) -} - -// UpdateOperator sets the "operator" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateOperator() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateOperator() - }) -} - -// ClearOperator clears the value of the "operator" field. -func (u *PackageBoxUpsertBulk) ClearOperator() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearOperator() - }) -} - -// SetContractNo sets the "contract_no" field. -func (u *PackageBoxUpsertBulk) SetContractNo(v string) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetContractNo(v) - }) -} - -// UpdateContractNo sets the "contract_no" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateContractNo() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateContractNo() - }) -} - -// ClearContractNo clears the value of the "contract_no" field. -func (u *PackageBoxUpsertBulk) ClearContractNo() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearContractNo() - }) -} - -// SetRemark sets the "remark" field. -func (u *PackageBoxUpsertBulk) SetRemark(v string) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetRemark(v) - }) -} - -// UpdateRemark sets the "remark" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateRemark() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateRemark() - }) -} - -// ClearRemark clears the value of the "remark" field. -func (u *PackageBoxUpsertBulk) ClearRemark() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearRemark() - }) -} - -// SetCreatedAt sets the "created_at" field. -func (u *PackageBoxUpsertBulk) SetCreatedAt(v int64) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetCreatedAt(v) - }) -} - -// AddCreatedAt adds v to the "created_at" field. -func (u *PackageBoxUpsertBulk) AddCreatedAt(v int64) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.AddCreatedAt(v) - }) -} - -// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateCreatedAt() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateCreatedAt() - }) -} - -// SetUpdatedAt sets the "updated_at" field. -func (u *PackageBoxUpsertBulk) SetUpdatedAt(v int64) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.SetUpdatedAt(v) - }) -} - -// AddUpdatedAt adds v to the "updated_at" field. -func (u *PackageBoxUpsertBulk) AddUpdatedAt(v int64) *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.AddUpdatedAt(v) - }) -} - -// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. -func (u *PackageBoxUpsertBulk) UpdateUpdatedAt() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.UpdateUpdatedAt() - }) -} - -// ClearUpdatedAt clears the value of the "updated_at" field. -func (u *PackageBoxUpsertBulk) ClearUpdatedAt() *PackageBoxUpsertBulk { - return u.Update(func(s *PackageBoxUpsert) { - s.ClearUpdatedAt() - }) -} - -// Exec executes the query. -func (u *PackageBoxUpsertBulk) Exec(ctx context.Context) error { - if u.create.err != nil { - return u.create.err - } - for i, b := range u.create.builders { - if len(b.conflict) != 0 { - return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the PackageBoxCreateBulk instead", i) - } - } - if len(u.create.conflict) == 0 { - return errors.New("ent: missing options for PackageBoxCreateBulk.OnConflict") - } - return u.create.Exec(ctx) -} - -// ExecX is like Exec, but panics if an error occurs. -func (u *PackageBoxUpsertBulk) ExecX(ctx context.Context) { - if err := u.create.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/bj_power_wms/ent/packagebox_update.go b/bj_power_wms/ent/packagebox_update.go deleted file mode 100644 index 494325f..0000000 --- a/bj_power_wms/ent/packagebox_update.go +++ /dev/null @@ -1,649 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "bj_power_wms/ent/packagebox" - "bj_power_wms/ent/predicate" - "context" - "errors" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// PackageBoxUpdate is the builder for updating PackageBox entities. -type PackageBoxUpdate struct { - config - hooks []Hook - mutation *PackageBoxMutation -} - -// Where appends a list predicates to the PackageBoxUpdate builder. -func (_u *PackageBoxUpdate) Where(ps ...predicate.PackageBox) *PackageBoxUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetBoxNo sets the "box_no" field. -func (_u *PackageBoxUpdate) SetBoxNo(v string) *PackageBoxUpdate { - _u.mutation.SetBoxNo(v) - return _u -} - -// SetNillableBoxNo sets the "box_no" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableBoxNo(v *string) *PackageBoxUpdate { - if v != nil { - _u.SetBoxNo(*v) - } - return _u -} - -// SetSnList sets the "sn_list" field. -func (_u *PackageBoxUpdate) SetSnList(v string) *PackageBoxUpdate { - _u.mutation.SetSnList(v) - return _u -} - -// SetNillableSnList sets the "sn_list" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableSnList(v *string) *PackageBoxUpdate { - if v != nil { - _u.SetSnList(*v) - } - return _u -} - -// ClearSnList clears the value of the "sn_list" field. -func (_u *PackageBoxUpdate) ClearSnList() *PackageBoxUpdate { - _u.mutation.ClearSnList() - return _u -} - -// SetMaterialCode sets the "material_code" field. -func (_u *PackageBoxUpdate) SetMaterialCode(v string) *PackageBoxUpdate { - _u.mutation.SetMaterialCode(v) - return _u -} - -// SetNillableMaterialCode sets the "material_code" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableMaterialCode(v *string) *PackageBoxUpdate { - if v != nil { - _u.SetMaterialCode(*v) - } - return _u -} - -// ClearMaterialCode clears the value of the "material_code" field. -func (_u *PackageBoxUpdate) ClearMaterialCode() *PackageBoxUpdate { - _u.mutation.ClearMaterialCode() - return _u -} - -// SetQuantity sets the "quantity" field. -func (_u *PackageBoxUpdate) SetQuantity(v int) *PackageBoxUpdate { - _u.mutation.ResetQuantity() - _u.mutation.SetQuantity(v) - return _u -} - -// SetNillableQuantity sets the "quantity" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableQuantity(v *int) *PackageBoxUpdate { - if v != nil { - _u.SetQuantity(*v) - } - return _u -} - -// AddQuantity adds value to the "quantity" field. -func (_u *PackageBoxUpdate) AddQuantity(v int) *PackageBoxUpdate { - _u.mutation.AddQuantity(v) - return _u -} - -// SetOperator sets the "operator" field. -func (_u *PackageBoxUpdate) SetOperator(v string) *PackageBoxUpdate { - _u.mutation.SetOperator(v) - return _u -} - -// SetNillableOperator sets the "operator" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableOperator(v *string) *PackageBoxUpdate { - if v != nil { - _u.SetOperator(*v) - } - return _u -} - -// ClearOperator clears the value of the "operator" field. -func (_u *PackageBoxUpdate) ClearOperator() *PackageBoxUpdate { - _u.mutation.ClearOperator() - return _u -} - -// SetContractNo sets the "contract_no" field. -func (_u *PackageBoxUpdate) SetContractNo(v string) *PackageBoxUpdate { - _u.mutation.SetContractNo(v) - return _u -} - -// SetNillableContractNo sets the "contract_no" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableContractNo(v *string) *PackageBoxUpdate { - if v != nil { - _u.SetContractNo(*v) - } - return _u -} - -// ClearContractNo clears the value of the "contract_no" field. -func (_u *PackageBoxUpdate) ClearContractNo() *PackageBoxUpdate { - _u.mutation.ClearContractNo() - return _u -} - -// SetRemark sets the "remark" field. -func (_u *PackageBoxUpdate) SetRemark(v string) *PackageBoxUpdate { - _u.mutation.SetRemark(v) - return _u -} - -// SetNillableRemark sets the "remark" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableRemark(v *string) *PackageBoxUpdate { - if v != nil { - _u.SetRemark(*v) - } - return _u -} - -// ClearRemark clears the value of the "remark" field. -func (_u *PackageBoxUpdate) ClearRemark() *PackageBoxUpdate { - _u.mutation.ClearRemark() - return _u -} - -// SetCreatedAt sets the "created_at" field. -func (_u *PackageBoxUpdate) SetCreatedAt(v int64) *PackageBoxUpdate { - _u.mutation.ResetCreatedAt() - _u.mutation.SetCreatedAt(v) - return _u -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableCreatedAt(v *int64) *PackageBoxUpdate { - if v != nil { - _u.SetCreatedAt(*v) - } - return _u -} - -// AddCreatedAt adds value to the "created_at" field. -func (_u *PackageBoxUpdate) AddCreatedAt(v int64) *PackageBoxUpdate { - _u.mutation.AddCreatedAt(v) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *PackageBoxUpdate) SetUpdatedAt(v int64) *PackageBoxUpdate { - _u.mutation.ResetUpdatedAt() - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_u *PackageBoxUpdate) SetNillableUpdatedAt(v *int64) *PackageBoxUpdate { - if v != nil { - _u.SetUpdatedAt(*v) - } - return _u -} - -// AddUpdatedAt adds value to the "updated_at" field. -func (_u *PackageBoxUpdate) AddUpdatedAt(v int64) *PackageBoxUpdate { - _u.mutation.AddUpdatedAt(v) - return _u -} - -// ClearUpdatedAt clears the value of the "updated_at" field. -func (_u *PackageBoxUpdate) ClearUpdatedAt() *PackageBoxUpdate { - _u.mutation.ClearUpdatedAt() - return _u -} - -// Mutation returns the PackageBoxMutation object of the builder. -func (_u *PackageBoxUpdate) Mutation() *PackageBoxMutation { - return _u.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *PackageBoxUpdate) Save(ctx context.Context) (int, error) { - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *PackageBoxUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *PackageBoxUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *PackageBoxUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -func (_u *PackageBoxUpdate) sqlSave(ctx context.Context) (_node int, err error) { - _spec := sqlgraph.NewUpdateSpec(packagebox.Table, packagebox.Columns, sqlgraph.NewFieldSpec(packagebox.FieldID, field.TypeInt)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.BoxNo(); ok { - _spec.SetField(packagebox.FieldBoxNo, field.TypeString, value) - } - if value, ok := _u.mutation.SnList(); ok { - _spec.SetField(packagebox.FieldSnList, field.TypeString, value) - } - if _u.mutation.SnListCleared() { - _spec.ClearField(packagebox.FieldSnList, field.TypeString) - } - if value, ok := _u.mutation.MaterialCode(); ok { - _spec.SetField(packagebox.FieldMaterialCode, field.TypeString, value) - } - if _u.mutation.MaterialCodeCleared() { - _spec.ClearField(packagebox.FieldMaterialCode, field.TypeString) - } - if value, ok := _u.mutation.Quantity(); ok { - _spec.SetField(packagebox.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedQuantity(); ok { - _spec.AddField(packagebox.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.Operator(); ok { - _spec.SetField(packagebox.FieldOperator, field.TypeString, value) - } - if _u.mutation.OperatorCleared() { - _spec.ClearField(packagebox.FieldOperator, field.TypeString) - } - if value, ok := _u.mutation.ContractNo(); ok { - _spec.SetField(packagebox.FieldContractNo, field.TypeString, value) - } - if _u.mutation.ContractNoCleared() { - _spec.ClearField(packagebox.FieldContractNo, field.TypeString) - } - if value, ok := _u.mutation.Remark(); ok { - _spec.SetField(packagebox.FieldRemark, field.TypeString, value) - } - if _u.mutation.RemarkCleared() { - _spec.ClearField(packagebox.FieldRemark, field.TypeString) - } - if value, ok := _u.mutation.CreatedAt(); ok { - _spec.SetField(packagebox.FieldCreatedAt, field.TypeInt64, value) - } - if value, ok := _u.mutation.AddedCreatedAt(); ok { - _spec.AddField(packagebox.FieldCreatedAt, field.TypeInt64, value) - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(packagebox.FieldUpdatedAt, field.TypeInt64, value) - } - if value, ok := _u.mutation.AddedUpdatedAt(); ok { - _spec.AddField(packagebox.FieldUpdatedAt, field.TypeInt64, value) - } - if _u.mutation.UpdatedAtCleared() { - _spec.ClearField(packagebox.FieldUpdatedAt, field.TypeInt64) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{packagebox.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// PackageBoxUpdateOne is the builder for updating a single PackageBox entity. -type PackageBoxUpdateOne struct { - config - fields []string - hooks []Hook - mutation *PackageBoxMutation -} - -// SetBoxNo sets the "box_no" field. -func (_u *PackageBoxUpdateOne) SetBoxNo(v string) *PackageBoxUpdateOne { - _u.mutation.SetBoxNo(v) - return _u -} - -// SetNillableBoxNo sets the "box_no" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableBoxNo(v *string) *PackageBoxUpdateOne { - if v != nil { - _u.SetBoxNo(*v) - } - return _u -} - -// SetSnList sets the "sn_list" field. -func (_u *PackageBoxUpdateOne) SetSnList(v string) *PackageBoxUpdateOne { - _u.mutation.SetSnList(v) - return _u -} - -// SetNillableSnList sets the "sn_list" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableSnList(v *string) *PackageBoxUpdateOne { - if v != nil { - _u.SetSnList(*v) - } - return _u -} - -// ClearSnList clears the value of the "sn_list" field. -func (_u *PackageBoxUpdateOne) ClearSnList() *PackageBoxUpdateOne { - _u.mutation.ClearSnList() - return _u -} - -// SetMaterialCode sets the "material_code" field. -func (_u *PackageBoxUpdateOne) SetMaterialCode(v string) *PackageBoxUpdateOne { - _u.mutation.SetMaterialCode(v) - return _u -} - -// SetNillableMaterialCode sets the "material_code" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableMaterialCode(v *string) *PackageBoxUpdateOne { - if v != nil { - _u.SetMaterialCode(*v) - } - return _u -} - -// ClearMaterialCode clears the value of the "material_code" field. -func (_u *PackageBoxUpdateOne) ClearMaterialCode() *PackageBoxUpdateOne { - _u.mutation.ClearMaterialCode() - return _u -} - -// SetQuantity sets the "quantity" field. -func (_u *PackageBoxUpdateOne) SetQuantity(v int) *PackageBoxUpdateOne { - _u.mutation.ResetQuantity() - _u.mutation.SetQuantity(v) - return _u -} - -// SetNillableQuantity sets the "quantity" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableQuantity(v *int) *PackageBoxUpdateOne { - if v != nil { - _u.SetQuantity(*v) - } - return _u -} - -// AddQuantity adds value to the "quantity" field. -func (_u *PackageBoxUpdateOne) AddQuantity(v int) *PackageBoxUpdateOne { - _u.mutation.AddQuantity(v) - return _u -} - -// SetOperator sets the "operator" field. -func (_u *PackageBoxUpdateOne) SetOperator(v string) *PackageBoxUpdateOne { - _u.mutation.SetOperator(v) - return _u -} - -// SetNillableOperator sets the "operator" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableOperator(v *string) *PackageBoxUpdateOne { - if v != nil { - _u.SetOperator(*v) - } - return _u -} - -// ClearOperator clears the value of the "operator" field. -func (_u *PackageBoxUpdateOne) ClearOperator() *PackageBoxUpdateOne { - _u.mutation.ClearOperator() - return _u -} - -// SetContractNo sets the "contract_no" field. -func (_u *PackageBoxUpdateOne) SetContractNo(v string) *PackageBoxUpdateOne { - _u.mutation.SetContractNo(v) - return _u -} - -// SetNillableContractNo sets the "contract_no" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableContractNo(v *string) *PackageBoxUpdateOne { - if v != nil { - _u.SetContractNo(*v) - } - return _u -} - -// ClearContractNo clears the value of the "contract_no" field. -func (_u *PackageBoxUpdateOne) ClearContractNo() *PackageBoxUpdateOne { - _u.mutation.ClearContractNo() - return _u -} - -// SetRemark sets the "remark" field. -func (_u *PackageBoxUpdateOne) SetRemark(v string) *PackageBoxUpdateOne { - _u.mutation.SetRemark(v) - return _u -} - -// SetNillableRemark sets the "remark" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableRemark(v *string) *PackageBoxUpdateOne { - if v != nil { - _u.SetRemark(*v) - } - return _u -} - -// ClearRemark clears the value of the "remark" field. -func (_u *PackageBoxUpdateOne) ClearRemark() *PackageBoxUpdateOne { - _u.mutation.ClearRemark() - return _u -} - -// SetCreatedAt sets the "created_at" field. -func (_u *PackageBoxUpdateOne) SetCreatedAt(v int64) *PackageBoxUpdateOne { - _u.mutation.ResetCreatedAt() - _u.mutation.SetCreatedAt(v) - return _u -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableCreatedAt(v *int64) *PackageBoxUpdateOne { - if v != nil { - _u.SetCreatedAt(*v) - } - return _u -} - -// AddCreatedAt adds value to the "created_at" field. -func (_u *PackageBoxUpdateOne) AddCreatedAt(v int64) *PackageBoxUpdateOne { - _u.mutation.AddCreatedAt(v) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *PackageBoxUpdateOne) SetUpdatedAt(v int64) *PackageBoxUpdateOne { - _u.mutation.ResetUpdatedAt() - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_u *PackageBoxUpdateOne) SetNillableUpdatedAt(v *int64) *PackageBoxUpdateOne { - if v != nil { - _u.SetUpdatedAt(*v) - } - return _u -} - -// AddUpdatedAt adds value to the "updated_at" field. -func (_u *PackageBoxUpdateOne) AddUpdatedAt(v int64) *PackageBoxUpdateOne { - _u.mutation.AddUpdatedAt(v) - return _u -} - -// ClearUpdatedAt clears the value of the "updated_at" field. -func (_u *PackageBoxUpdateOne) ClearUpdatedAt() *PackageBoxUpdateOne { - _u.mutation.ClearUpdatedAt() - return _u -} - -// Mutation returns the PackageBoxMutation object of the builder. -func (_u *PackageBoxUpdateOne) Mutation() *PackageBoxMutation { - return _u.mutation -} - -// Where appends a list predicates to the PackageBoxUpdate builder. -func (_u *PackageBoxUpdateOne) Where(ps ...predicate.PackageBox) *PackageBoxUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *PackageBoxUpdateOne) Select(field string, fields ...string) *PackageBoxUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated PackageBox entity. -func (_u *PackageBoxUpdateOne) Save(ctx context.Context) (*PackageBox, error) { - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *PackageBoxUpdateOne) SaveX(ctx context.Context) *PackageBox { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *PackageBoxUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *PackageBoxUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -func (_u *PackageBoxUpdateOne) sqlSave(ctx context.Context) (_node *PackageBox, err error) { - _spec := sqlgraph.NewUpdateSpec(packagebox.Table, packagebox.Columns, sqlgraph.NewFieldSpec(packagebox.FieldID, field.TypeInt)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PackageBox.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, packagebox.FieldID) - for _, f := range fields { - if !packagebox.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != packagebox.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.BoxNo(); ok { - _spec.SetField(packagebox.FieldBoxNo, field.TypeString, value) - } - if value, ok := _u.mutation.SnList(); ok { - _spec.SetField(packagebox.FieldSnList, field.TypeString, value) - } - if _u.mutation.SnListCleared() { - _spec.ClearField(packagebox.FieldSnList, field.TypeString) - } - if value, ok := _u.mutation.MaterialCode(); ok { - _spec.SetField(packagebox.FieldMaterialCode, field.TypeString, value) - } - if _u.mutation.MaterialCodeCleared() { - _spec.ClearField(packagebox.FieldMaterialCode, field.TypeString) - } - if value, ok := _u.mutation.Quantity(); ok { - _spec.SetField(packagebox.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedQuantity(); ok { - _spec.AddField(packagebox.FieldQuantity, field.TypeInt, value) - } - if value, ok := _u.mutation.Operator(); ok { - _spec.SetField(packagebox.FieldOperator, field.TypeString, value) - } - if _u.mutation.OperatorCleared() { - _spec.ClearField(packagebox.FieldOperator, field.TypeString) - } - if value, ok := _u.mutation.ContractNo(); ok { - _spec.SetField(packagebox.FieldContractNo, field.TypeString, value) - } - if _u.mutation.ContractNoCleared() { - _spec.ClearField(packagebox.FieldContractNo, field.TypeString) - } - if value, ok := _u.mutation.Remark(); ok { - _spec.SetField(packagebox.FieldRemark, field.TypeString, value) - } - if _u.mutation.RemarkCleared() { - _spec.ClearField(packagebox.FieldRemark, field.TypeString) - } - if value, ok := _u.mutation.CreatedAt(); ok { - _spec.SetField(packagebox.FieldCreatedAt, field.TypeInt64, value) - } - if value, ok := _u.mutation.AddedCreatedAt(); ok { - _spec.AddField(packagebox.FieldCreatedAt, field.TypeInt64, value) - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(packagebox.FieldUpdatedAt, field.TypeInt64, value) - } - if value, ok := _u.mutation.AddedUpdatedAt(); ok { - _spec.AddField(packagebox.FieldUpdatedAt, field.TypeInt64, value) - } - if _u.mutation.UpdatedAtCleared() { - _spec.ClearField(packagebox.FieldUpdatedAt, field.TypeInt64) - } - _node = &PackageBox{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{packagebox.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -} diff --git a/bj_power_wms/ent/packagebox.go b/bj_power_wms/ent/permission.go similarity index 52% rename from bj_power_wms/ent/packagebox.go rename to bj_power_wms/ent/permission.go index 6a24fe9..3072b27 100644 --- a/bj_power_wms/ent/packagebox.go +++ b/bj_power_wms/ent/permission.go @@ -3,7 +3,7 @@ package ent import ( - "bj_power_wms/ent/packagebox" + "bj_power_wms/ent/permission" "fmt" "strings" @@ -11,26 +11,26 @@ import ( "entgo.io/ent/dialect/sql" ) -// PackageBox is the model entity for the PackageBox schema. -type PackageBox struct { +// Permission is the model entity for the Permission schema. +type Permission struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` - // 箱号 - BoxNo string `json:"boxNo,omitempty"` - // 箱内 SN 列表 - SnList string `json:"snList,omitempty"` - // 物料编码 - MaterialCode string `json:"materialCode,omitempty"` - // 箱内数量 - Quantity int `json:"quantity,omitempty"` - // 包装人 - Operator string `json:"operator,omitempty"` - // 合同号(选填) - ContractNo string `json:"contractNo,omitempty"` + // 权限编码,如 inbound:view + Code string `json:"code,omitempty"` + // 名称 + Name string `json:"name,omitempty"` + // 类型 MENU菜单/BUTTON按钮 + Type string `json:"type,omitempty"` + // 前端路由(菜单类) + Path string `json:"path,omitempty"` + // 图标(菜单类) + Icon string `json:"icon,omitempty"` + // 排序 + Sort int `json:"sort,omitempty"` // 备注 Remark string `json:"remark,omitempty"` - // CreatedAt holds the value of the "created_at" field. + // 创建时间 CreatedAt int64 `json:"createdAt,omitempty"` // 更新时间 UpdatedAt int64 `json:"updatedAt,omitempty"` @@ -38,13 +38,13 @@ type PackageBox struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*PackageBox) scanValues(columns []string) ([]any, error) { +func (*Permission) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case packagebox.FieldID, packagebox.FieldQuantity, packagebox.FieldCreatedAt, packagebox.FieldUpdatedAt: + case permission.FieldID, permission.FieldSort, permission.FieldCreatedAt, permission.FieldUpdatedAt: values[i] = new(sql.NullInt64) - case packagebox.FieldBoxNo, packagebox.FieldSnList, packagebox.FieldMaterialCode, packagebox.FieldOperator, packagebox.FieldContractNo, packagebox.FieldRemark: + case permission.FieldCode, permission.FieldName, permission.FieldType, permission.FieldPath, permission.FieldIcon, permission.FieldRemark: values[i] = new(sql.NullString) default: values[i] = new(sql.UnknownType) @@ -54,68 +54,68 @@ func (*PackageBox) scanValues(columns []string) ([]any, error) { } // assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the PackageBox fields. -func (_m *PackageBox) assignValues(columns []string, values []any) error { +// to the Permission fields. +func (_m *Permission) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } for i := range columns { switch columns[i] { - case packagebox.FieldID: + case permission.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } _m.ID = int(value.Int64) - case packagebox.FieldBoxNo: + case permission.FieldCode: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field box_no", values[i]) + return fmt.Errorf("unexpected type %T for field code", values[i]) } else if value.Valid { - _m.BoxNo = value.String + _m.Code = value.String } - case packagebox.FieldSnList: + case permission.FieldName: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field sn_list", values[i]) + return fmt.Errorf("unexpected type %T for field name", values[i]) } else if value.Valid { - _m.SnList = value.String + _m.Name = value.String } - case packagebox.FieldMaterialCode: + case permission.FieldType: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field material_code", values[i]) + return fmt.Errorf("unexpected type %T for field type", values[i]) } else if value.Valid { - _m.MaterialCode = value.String + _m.Type = value.String } - case packagebox.FieldQuantity: + case permission.FieldPath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field path", values[i]) + } else if value.Valid { + _m.Path = value.String + } + case permission.FieldIcon: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field icon", values[i]) + } else if value.Valid { + _m.Icon = value.String + } + case permission.FieldSort: if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field quantity", values[i]) + return fmt.Errorf("unexpected type %T for field sort", values[i]) } else if value.Valid { - _m.Quantity = int(value.Int64) + _m.Sort = int(value.Int64) } - case packagebox.FieldOperator: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field operator", values[i]) - } else if value.Valid { - _m.Operator = value.String - } - case packagebox.FieldContractNo: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field contract_no", values[i]) - } else if value.Valid { - _m.ContractNo = value.String - } - case packagebox.FieldRemark: + case permission.FieldRemark: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field remark", values[i]) } else if value.Valid { _m.Remark = value.String } - case packagebox.FieldCreatedAt: + case permission.FieldCreatedAt: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { _m.CreatedAt = value.Int64 } - case packagebox.FieldUpdatedAt: + case permission.FieldUpdatedAt: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field updated_at", values[i]) } else if value.Valid { @@ -128,52 +128,52 @@ func (_m *PackageBox) assignValues(columns []string, values []any) error { return nil } -// Value returns the ent.Value that was dynamically selected and assigned to the PackageBox. +// Value returns the ent.Value that was dynamically selected and assigned to the Permission. // This includes values selected through modifiers, order, etc. -func (_m *PackageBox) Value(name string) (ent.Value, error) { +func (_m *Permission) Value(name string) (ent.Value, error) { return _m.selectValues.Get(name) } -// Update returns a builder for updating this PackageBox. -// Note that you need to call PackageBox.Unwrap() before calling this method if this PackageBox +// Update returns a builder for updating this Permission. +// Note that you need to call Permission.Unwrap() before calling this method if this Permission // was returned from a transaction, and the transaction was committed or rolled back. -func (_m *PackageBox) Update() *PackageBoxUpdateOne { - return NewPackageBoxClient(_m.config).UpdateOne(_m) +func (_m *Permission) Update() *PermissionUpdateOne { + return NewPermissionClient(_m.config).UpdateOne(_m) } -// Unwrap unwraps the PackageBox entity that was returned from a transaction after it was closed, +// Unwrap unwraps the Permission entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. -func (_m *PackageBox) Unwrap() *PackageBox { +func (_m *Permission) Unwrap() *Permission { _tx, ok := _m.config.driver.(*txDriver) if !ok { - panic("ent: PackageBox is not a transactional entity") + panic("ent: Permission is not a transactional entity") } _m.config.driver = _tx.drv return _m } // String implements the fmt.Stringer. -func (_m *PackageBox) String() string { +func (_m *Permission) String() string { var builder strings.Builder - builder.WriteString("PackageBox(") + builder.WriteString("Permission(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("box_no=") - builder.WriteString(_m.BoxNo) + builder.WriteString("code=") + builder.WriteString(_m.Code) builder.WriteString(", ") - builder.WriteString("sn_list=") - builder.WriteString(_m.SnList) + builder.WriteString("name=") + builder.WriteString(_m.Name) builder.WriteString(", ") - builder.WriteString("material_code=") - builder.WriteString(_m.MaterialCode) + builder.WriteString("type=") + builder.WriteString(_m.Type) builder.WriteString(", ") - builder.WriteString("quantity=") - builder.WriteString(fmt.Sprintf("%v", _m.Quantity)) + builder.WriteString("path=") + builder.WriteString(_m.Path) builder.WriteString(", ") - builder.WriteString("operator=") - builder.WriteString(_m.Operator) + builder.WriteString("icon=") + builder.WriteString(_m.Icon) builder.WriteString(", ") - builder.WriteString("contract_no=") - builder.WriteString(_m.ContractNo) + builder.WriteString("sort=") + builder.WriteString(fmt.Sprintf("%v", _m.Sort)) builder.WriteString(", ") builder.WriteString("remark=") builder.WriteString(_m.Remark) @@ -187,5 +187,5 @@ func (_m *PackageBox) String() string { return builder.String() } -// PackageBoxes is a parsable slice of PackageBox. -type PackageBoxes []*PackageBox +// Permissions is a parsable slice of Permission. +type Permissions []*Permission diff --git a/bj_power_wms/ent/permission/permission.go b/bj_power_wms/ent/permission/permission.go new file mode 100644 index 0000000..caf7068 --- /dev/null +++ b/bj_power_wms/ent/permission/permission.go @@ -0,0 +1,140 @@ +// Code generated by ent, DO NOT EDIT. + +package permission + +import ( + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the permission type in the database. + Label = "permission" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCode holds the string denoting the code field in the database. + FieldCode = "code" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldType holds the string denoting the type field in the database. + FieldType = "type" + // FieldPath holds the string denoting the path field in the database. + FieldPath = "path" + // FieldIcon holds the string denoting the icon field in the database. + FieldIcon = "icon" + // FieldSort holds the string denoting the sort field in the database. + FieldSort = "sort" + // FieldRemark holds the string denoting the remark field in the database. + FieldRemark = "remark" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // Table holds the table name of the permission in the database. + Table = "permissions" +) + +// Columns holds all SQL columns for permission fields. +var Columns = []string{ + FieldID, + FieldCode, + FieldName, + FieldType, + FieldPath, + FieldIcon, + FieldSort, + FieldRemark, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // CodeValidator is a validator for the "code" field. It is called by the builders before save. + CodeValidator func(string) error + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // DefaultType holds the default value on creation for the "type" field. + DefaultType string + // TypeValidator is a validator for the "type" field. It is called by the builders before save. + TypeValidator func(string) error + // DefaultPath holds the default value on creation for the "path" field. + DefaultPath string + // PathValidator is a validator for the "path" field. It is called by the builders before save. + PathValidator func(string) error + // DefaultIcon holds the default value on creation for the "icon" field. + DefaultIcon string + // IconValidator is a validator for the "icon" field. It is called by the builders before save. + IconValidator func(string) error + // DefaultSort holds the default value on creation for the "sort" field. + DefaultSort int + // DefaultRemark holds the default value on creation for the "remark" field. + DefaultRemark string + // RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + RemarkValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() int64 + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() int64 +) + +// OrderOption defines the ordering options for the Permission queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCode orders the results by the code field. +func ByCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCode, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByType orders the results by the type field. +func ByType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldType, opts...).ToFunc() +} + +// ByPath orders the results by the path field. +func ByPath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPath, opts...).ToFunc() +} + +// ByIcon orders the results by the icon field. +func ByIcon(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIcon, opts...).ToFunc() +} + +// BySort orders the results by the sort field. +func BySort(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSort, opts...).ToFunc() +} + +// ByRemark orders the results by the remark field. +func ByRemark(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRemark, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} diff --git a/bj_power_wms/ent/permission/where.go b/bj_power_wms/ent/permission/where.go new file mode 100644 index 0000000..0b4c16c --- /dev/null +++ b/bj_power_wms/ent/permission/where.go @@ -0,0 +1,664 @@ +// Code generated by ent, DO NOT EDIT. + +package permission + +import ( + "bj_power_wms/ent/predicate" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldID, id)) +} + +// Code applies equality check predicate on the "code" field. It's identical to CodeEQ. +func Code(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldCode, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldName, v)) +} + +// Type applies equality check predicate on the "type" field. It's identical to TypeEQ. +func Type(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldType, v)) +} + +// Path applies equality check predicate on the "path" field. It's identical to PathEQ. +func Path(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldPath, v)) +} + +// Icon applies equality check predicate on the "icon" field. It's identical to IconEQ. +func Icon(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldIcon, v)) +} + +// Sort applies equality check predicate on the "sort" field. It's identical to SortEQ. +func Sort(v int) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldSort, v)) +} + +// Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. +func Remark(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldRemark, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v int64) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v int64) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// CodeEQ applies the EQ predicate on the "code" field. +func CodeEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldCode, v)) +} + +// CodeNEQ applies the NEQ predicate on the "code" field. +func CodeNEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldCode, v)) +} + +// CodeIn applies the In predicate on the "code" field. +func CodeIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldCode, vs...)) +} + +// CodeNotIn applies the NotIn predicate on the "code" field. +func CodeNotIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldCode, vs...)) +} + +// CodeGT applies the GT predicate on the "code" field. +func CodeGT(v string) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldCode, v)) +} + +// CodeGTE applies the GTE predicate on the "code" field. +func CodeGTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldCode, v)) +} + +// CodeLT applies the LT predicate on the "code" field. +func CodeLT(v string) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldCode, v)) +} + +// CodeLTE applies the LTE predicate on the "code" field. +func CodeLTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldCode, v)) +} + +// CodeContains applies the Contains predicate on the "code" field. +func CodeContains(v string) predicate.Permission { + return predicate.Permission(sql.FieldContains(FieldCode, v)) +} + +// CodeHasPrefix applies the HasPrefix predicate on the "code" field. +func CodeHasPrefix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasPrefix(FieldCode, v)) +} + +// CodeHasSuffix applies the HasSuffix predicate on the "code" field. +func CodeHasSuffix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasSuffix(FieldCode, v)) +} + +// CodeEqualFold applies the EqualFold predicate on the "code" field. +func CodeEqualFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldEqualFold(FieldCode, v)) +} + +// CodeContainsFold applies the ContainsFold predicate on the "code" field. +func CodeContainsFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldContainsFold(FieldCode, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Permission { + return predicate.Permission(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldContainsFold(FieldName, v)) +} + +// TypeEQ applies the EQ predicate on the "type" field. +func TypeEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldType, v)) +} + +// TypeNEQ applies the NEQ predicate on the "type" field. +func TypeNEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldType, v)) +} + +// TypeIn applies the In predicate on the "type" field. +func TypeIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldType, vs...)) +} + +// TypeNotIn applies the NotIn predicate on the "type" field. +func TypeNotIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldType, vs...)) +} + +// TypeGT applies the GT predicate on the "type" field. +func TypeGT(v string) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldType, v)) +} + +// TypeGTE applies the GTE predicate on the "type" field. +func TypeGTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldType, v)) +} + +// TypeLT applies the LT predicate on the "type" field. +func TypeLT(v string) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldType, v)) +} + +// TypeLTE applies the LTE predicate on the "type" field. +func TypeLTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldType, v)) +} + +// TypeContains applies the Contains predicate on the "type" field. +func TypeContains(v string) predicate.Permission { + return predicate.Permission(sql.FieldContains(FieldType, v)) +} + +// TypeHasPrefix applies the HasPrefix predicate on the "type" field. +func TypeHasPrefix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasPrefix(FieldType, v)) +} + +// TypeHasSuffix applies the HasSuffix predicate on the "type" field. +func TypeHasSuffix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasSuffix(FieldType, v)) +} + +// TypeEqualFold applies the EqualFold predicate on the "type" field. +func TypeEqualFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldEqualFold(FieldType, v)) +} + +// TypeContainsFold applies the ContainsFold predicate on the "type" field. +func TypeContainsFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldContainsFold(FieldType, v)) +} + +// PathEQ applies the EQ predicate on the "path" field. +func PathEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldPath, v)) +} + +// PathNEQ applies the NEQ predicate on the "path" field. +func PathNEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldPath, v)) +} + +// PathIn applies the In predicate on the "path" field. +func PathIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldPath, vs...)) +} + +// PathNotIn applies the NotIn predicate on the "path" field. +func PathNotIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldPath, vs...)) +} + +// PathGT applies the GT predicate on the "path" field. +func PathGT(v string) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldPath, v)) +} + +// PathGTE applies the GTE predicate on the "path" field. +func PathGTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldPath, v)) +} + +// PathLT applies the LT predicate on the "path" field. +func PathLT(v string) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldPath, v)) +} + +// PathLTE applies the LTE predicate on the "path" field. +func PathLTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldPath, v)) +} + +// PathContains applies the Contains predicate on the "path" field. +func PathContains(v string) predicate.Permission { + return predicate.Permission(sql.FieldContains(FieldPath, v)) +} + +// PathHasPrefix applies the HasPrefix predicate on the "path" field. +func PathHasPrefix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasPrefix(FieldPath, v)) +} + +// PathHasSuffix applies the HasSuffix predicate on the "path" field. +func PathHasSuffix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasSuffix(FieldPath, v)) +} + +// PathIsNil applies the IsNil predicate on the "path" field. +func PathIsNil() predicate.Permission { + return predicate.Permission(sql.FieldIsNull(FieldPath)) +} + +// PathNotNil applies the NotNil predicate on the "path" field. +func PathNotNil() predicate.Permission { + return predicate.Permission(sql.FieldNotNull(FieldPath)) +} + +// PathEqualFold applies the EqualFold predicate on the "path" field. +func PathEqualFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldEqualFold(FieldPath, v)) +} + +// PathContainsFold applies the ContainsFold predicate on the "path" field. +func PathContainsFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldContainsFold(FieldPath, v)) +} + +// IconEQ applies the EQ predicate on the "icon" field. +func IconEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldIcon, v)) +} + +// IconNEQ applies the NEQ predicate on the "icon" field. +func IconNEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldIcon, v)) +} + +// IconIn applies the In predicate on the "icon" field. +func IconIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldIcon, vs...)) +} + +// IconNotIn applies the NotIn predicate on the "icon" field. +func IconNotIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldIcon, vs...)) +} + +// IconGT applies the GT predicate on the "icon" field. +func IconGT(v string) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldIcon, v)) +} + +// IconGTE applies the GTE predicate on the "icon" field. +func IconGTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldIcon, v)) +} + +// IconLT applies the LT predicate on the "icon" field. +func IconLT(v string) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldIcon, v)) +} + +// IconLTE applies the LTE predicate on the "icon" field. +func IconLTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldIcon, v)) +} + +// IconContains applies the Contains predicate on the "icon" field. +func IconContains(v string) predicate.Permission { + return predicate.Permission(sql.FieldContains(FieldIcon, v)) +} + +// IconHasPrefix applies the HasPrefix predicate on the "icon" field. +func IconHasPrefix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasPrefix(FieldIcon, v)) +} + +// IconHasSuffix applies the HasSuffix predicate on the "icon" field. +func IconHasSuffix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasSuffix(FieldIcon, v)) +} + +// IconIsNil applies the IsNil predicate on the "icon" field. +func IconIsNil() predicate.Permission { + return predicate.Permission(sql.FieldIsNull(FieldIcon)) +} + +// IconNotNil applies the NotNil predicate on the "icon" field. +func IconNotNil() predicate.Permission { + return predicate.Permission(sql.FieldNotNull(FieldIcon)) +} + +// IconEqualFold applies the EqualFold predicate on the "icon" field. +func IconEqualFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldEqualFold(FieldIcon, v)) +} + +// IconContainsFold applies the ContainsFold predicate on the "icon" field. +func IconContainsFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldContainsFold(FieldIcon, v)) +} + +// SortEQ applies the EQ predicate on the "sort" field. +func SortEQ(v int) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldSort, v)) +} + +// SortNEQ applies the NEQ predicate on the "sort" field. +func SortNEQ(v int) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldSort, v)) +} + +// SortIn applies the In predicate on the "sort" field. +func SortIn(vs ...int) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldSort, vs...)) +} + +// SortNotIn applies the NotIn predicate on the "sort" field. +func SortNotIn(vs ...int) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldSort, vs...)) +} + +// SortGT applies the GT predicate on the "sort" field. +func SortGT(v int) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldSort, v)) +} + +// SortGTE applies the GTE predicate on the "sort" field. +func SortGTE(v int) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldSort, v)) +} + +// SortLT applies the LT predicate on the "sort" field. +func SortLT(v int) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldSort, v)) +} + +// SortLTE applies the LTE predicate on the "sort" field. +func SortLTE(v int) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldSort, v)) +} + +// SortIsNil applies the IsNil predicate on the "sort" field. +func SortIsNil() predicate.Permission { + return predicate.Permission(sql.FieldIsNull(FieldSort)) +} + +// SortNotNil applies the NotNil predicate on the "sort" field. +func SortNotNil() predicate.Permission { + return predicate.Permission(sql.FieldNotNull(FieldSort)) +} + +// RemarkEQ applies the EQ predicate on the "remark" field. +func RemarkEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldRemark, v)) +} + +// RemarkNEQ applies the NEQ predicate on the "remark" field. +func RemarkNEQ(v string) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldRemark, v)) +} + +// RemarkIn applies the In predicate on the "remark" field. +func RemarkIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldRemark, vs...)) +} + +// RemarkNotIn applies the NotIn predicate on the "remark" field. +func RemarkNotIn(vs ...string) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldRemark, vs...)) +} + +// RemarkGT applies the GT predicate on the "remark" field. +func RemarkGT(v string) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldRemark, v)) +} + +// RemarkGTE applies the GTE predicate on the "remark" field. +func RemarkGTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldRemark, v)) +} + +// RemarkLT applies the LT predicate on the "remark" field. +func RemarkLT(v string) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldRemark, v)) +} + +// RemarkLTE applies the LTE predicate on the "remark" field. +func RemarkLTE(v string) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldRemark, v)) +} + +// RemarkContains applies the Contains predicate on the "remark" field. +func RemarkContains(v string) predicate.Permission { + return predicate.Permission(sql.FieldContains(FieldRemark, v)) +} + +// RemarkHasPrefix applies the HasPrefix predicate on the "remark" field. +func RemarkHasPrefix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasPrefix(FieldRemark, v)) +} + +// RemarkHasSuffix applies the HasSuffix predicate on the "remark" field. +func RemarkHasSuffix(v string) predicate.Permission { + return predicate.Permission(sql.FieldHasSuffix(FieldRemark, v)) +} + +// RemarkIsNil applies the IsNil predicate on the "remark" field. +func RemarkIsNil() predicate.Permission { + return predicate.Permission(sql.FieldIsNull(FieldRemark)) +} + +// RemarkNotNil applies the NotNil predicate on the "remark" field. +func RemarkNotNil() predicate.Permission { + return predicate.Permission(sql.FieldNotNull(FieldRemark)) +} + +// RemarkEqualFold applies the EqualFold predicate on the "remark" field. +func RemarkEqualFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldEqualFold(FieldRemark, v)) +} + +// RemarkContainsFold applies the ContainsFold predicate on the "remark" field. +func RemarkContainsFold(v string) predicate.Permission { + return predicate.Permission(sql.FieldContainsFold(FieldRemark, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v int64) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v int64) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...int64) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...int64) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v int64) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v int64) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v int64) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v int64) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v int64) predicate.Permission { + return predicate.Permission(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v int64) predicate.Permission { + return predicate.Permission(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...int64) predicate.Permission { + return predicate.Permission(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...int64) predicate.Permission { + return predicate.Permission(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v int64) predicate.Permission { + return predicate.Permission(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v int64) predicate.Permission { + return predicate.Permission(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v int64) predicate.Permission { + return predicate.Permission(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v int64) predicate.Permission { + return predicate.Permission(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Permission) predicate.Permission { + return predicate.Permission(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Permission) predicate.Permission { + return predicate.Permission(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Permission) predicate.Permission { + return predicate.Permission(sql.NotPredicates(p)) +} diff --git a/bj_power_wms/ent/permission_create.go b/bj_power_wms/ent/permission_create.go new file mode 100644 index 0000000..92745a3 --- /dev/null +++ b/bj_power_wms/ent/permission_create.go @@ -0,0 +1,1126 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/permission" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// PermissionCreate is the builder for creating a Permission entity. +type PermissionCreate struct { + config + mutation *PermissionMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetCode sets the "code" field. +func (_c *PermissionCreate) SetCode(v string) *PermissionCreate { + _c.mutation.SetCode(v) + return _c +} + +// SetName sets the "name" field. +func (_c *PermissionCreate) SetName(v string) *PermissionCreate { + _c.mutation.SetName(v) + return _c +} + +// SetType sets the "type" field. +func (_c *PermissionCreate) SetType(v string) *PermissionCreate { + _c.mutation.SetType(v) + return _c +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_c *PermissionCreate) SetNillableType(v *string) *PermissionCreate { + if v != nil { + _c.SetType(*v) + } + return _c +} + +// SetPath sets the "path" field. +func (_c *PermissionCreate) SetPath(v string) *PermissionCreate { + _c.mutation.SetPath(v) + return _c +} + +// SetNillablePath sets the "path" field if the given value is not nil. +func (_c *PermissionCreate) SetNillablePath(v *string) *PermissionCreate { + if v != nil { + _c.SetPath(*v) + } + return _c +} + +// SetIcon sets the "icon" field. +func (_c *PermissionCreate) SetIcon(v string) *PermissionCreate { + _c.mutation.SetIcon(v) + return _c +} + +// SetNillableIcon sets the "icon" field if the given value is not nil. +func (_c *PermissionCreate) SetNillableIcon(v *string) *PermissionCreate { + if v != nil { + _c.SetIcon(*v) + } + return _c +} + +// SetSort sets the "sort" field. +func (_c *PermissionCreate) SetSort(v int) *PermissionCreate { + _c.mutation.SetSort(v) + return _c +} + +// SetNillableSort sets the "sort" field if the given value is not nil. +func (_c *PermissionCreate) SetNillableSort(v *int) *PermissionCreate { + if v != nil { + _c.SetSort(*v) + } + return _c +} + +// SetRemark sets the "remark" field. +func (_c *PermissionCreate) SetRemark(v string) *PermissionCreate { + _c.mutation.SetRemark(v) + return _c +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_c *PermissionCreate) SetNillableRemark(v *string) *PermissionCreate { + if v != nil { + _c.SetRemark(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *PermissionCreate) SetCreatedAt(v int64) *PermissionCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *PermissionCreate) SetNillableCreatedAt(v *int64) *PermissionCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *PermissionCreate) SetUpdatedAt(v int64) *PermissionCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *PermissionCreate) SetNillableUpdatedAt(v *int64) *PermissionCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// Mutation returns the PermissionMutation object of the builder. +func (_c *PermissionCreate) Mutation() *PermissionMutation { + return _c.mutation +} + +// Save creates the Permission in the database. +func (_c *PermissionCreate) Save(ctx context.Context) (*Permission, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *PermissionCreate) SaveX(ctx context.Context) *Permission { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *PermissionCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *PermissionCreate) 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 *PermissionCreate) defaults() { + if _, ok := _c.mutation.GetType(); !ok { + v := permission.DefaultType + _c.mutation.SetType(v) + } + if _, ok := _c.mutation.Path(); !ok { + v := permission.DefaultPath + _c.mutation.SetPath(v) + } + if _, ok := _c.mutation.Icon(); !ok { + v := permission.DefaultIcon + _c.mutation.SetIcon(v) + } + if _, ok := _c.mutation.Sort(); !ok { + v := permission.DefaultSort + _c.mutation.SetSort(v) + } + if _, ok := _c.mutation.Remark(); !ok { + v := permission.DefaultRemark + _c.mutation.SetRemark(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := permission.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := permission.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *PermissionCreate) check() error { + if _, ok := _c.mutation.Code(); !ok { + return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "Permission.code"`)} + } + if v, ok := _c.mutation.Code(); ok { + if err := permission.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Permission.code": %w`, err)} + } + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Permission.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := permission.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Permission.name": %w`, err)} + } + } + if _, ok := _c.mutation.GetType(); !ok { + return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Permission.type"`)} + } + if v, ok := _c.mutation.GetType(); ok { + if err := permission.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Permission.type": %w`, err)} + } + } + if v, ok := _c.mutation.Path(); ok { + if err := permission.PathValidator(v); err != nil { + return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Permission.path": %w`, err)} + } + } + if v, ok := _c.mutation.Icon(); ok { + if err := permission.IconValidator(v); err != nil { + return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Permission.icon": %w`, err)} + } + } + if v, ok := _c.mutation.Remark(); ok { + if err := permission.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Permission.remark": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Permission.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Permission.updated_at"`)} + } + return nil +} + +func (_c *PermissionCreate) sqlSave(ctx context.Context) (*Permission, 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 + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *PermissionCreate) createSpec() (*Permission, *sqlgraph.CreateSpec) { + var ( + _node = &Permission{config: _c.config} + _spec = sqlgraph.NewCreateSpec(permission.Table, sqlgraph.NewFieldSpec(permission.FieldID, field.TypeInt)) + ) + _spec.OnConflict = _c.conflict + if value, ok := _c.mutation.Code(); ok { + _spec.SetField(permission.FieldCode, field.TypeString, value) + _node.Code = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(permission.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.GetType(); ok { + _spec.SetField(permission.FieldType, field.TypeString, value) + _node.Type = value + } + if value, ok := _c.mutation.Path(); ok { + _spec.SetField(permission.FieldPath, field.TypeString, value) + _node.Path = value + } + if value, ok := _c.mutation.Icon(); ok { + _spec.SetField(permission.FieldIcon, field.TypeString, value) + _node.Icon = value + } + if value, ok := _c.mutation.Sort(); ok { + _spec.SetField(permission.FieldSort, field.TypeInt, value) + _node.Sort = value + } + if value, ok := _c.mutation.Remark(); ok { + _spec.SetField(permission.FieldRemark, field.TypeString, value) + _node.Remark = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(permission.FieldCreatedAt, field.TypeInt64, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(permission.FieldUpdatedAt, field.TypeInt64, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Permission.Create(). +// SetCode(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.PermissionUpsert) { +// SetCode(v+v). +// }). +// Exec(ctx) +func (_c *PermissionCreate) OnConflict(opts ...sql.ConflictOption) *PermissionUpsertOne { + _c.conflict = opts + return &PermissionUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Permission.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *PermissionCreate) OnConflictColumns(columns ...string) *PermissionUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &PermissionUpsertOne{ + create: _c, + } +} + +type ( + // PermissionUpsertOne is the builder for "upsert"-ing + // one Permission node. + PermissionUpsertOne struct { + create *PermissionCreate + } + + // PermissionUpsert is the "OnConflict" setter. + PermissionUpsert struct { + *sql.UpdateSet + } +) + +// SetCode sets the "code" field. +func (u *PermissionUpsert) SetCode(v string) *PermissionUpsert { + u.Set(permission.FieldCode, v) + return u +} + +// UpdateCode sets the "code" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateCode() *PermissionUpsert { + u.SetExcluded(permission.FieldCode) + return u +} + +// SetName sets the "name" field. +func (u *PermissionUpsert) SetName(v string) *PermissionUpsert { + u.Set(permission.FieldName, v) + return u +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateName() *PermissionUpsert { + u.SetExcluded(permission.FieldName) + return u +} + +// SetType sets the "type" field. +func (u *PermissionUpsert) SetType(v string) *PermissionUpsert { + u.Set(permission.FieldType, v) + return u +} + +// UpdateType sets the "type" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateType() *PermissionUpsert { + u.SetExcluded(permission.FieldType) + return u +} + +// SetPath sets the "path" field. +func (u *PermissionUpsert) SetPath(v string) *PermissionUpsert { + u.Set(permission.FieldPath, v) + return u +} + +// UpdatePath sets the "path" field to the value that was provided on create. +func (u *PermissionUpsert) UpdatePath() *PermissionUpsert { + u.SetExcluded(permission.FieldPath) + return u +} + +// ClearPath clears the value of the "path" field. +func (u *PermissionUpsert) ClearPath() *PermissionUpsert { + u.SetNull(permission.FieldPath) + return u +} + +// SetIcon sets the "icon" field. +func (u *PermissionUpsert) SetIcon(v string) *PermissionUpsert { + u.Set(permission.FieldIcon, v) + return u +} + +// UpdateIcon sets the "icon" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateIcon() *PermissionUpsert { + u.SetExcluded(permission.FieldIcon) + return u +} + +// ClearIcon clears the value of the "icon" field. +func (u *PermissionUpsert) ClearIcon() *PermissionUpsert { + u.SetNull(permission.FieldIcon) + return u +} + +// SetSort sets the "sort" field. +func (u *PermissionUpsert) SetSort(v int) *PermissionUpsert { + u.Set(permission.FieldSort, v) + return u +} + +// UpdateSort sets the "sort" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateSort() *PermissionUpsert { + u.SetExcluded(permission.FieldSort) + return u +} + +// AddSort adds v to the "sort" field. +func (u *PermissionUpsert) AddSort(v int) *PermissionUpsert { + u.Add(permission.FieldSort, v) + return u +} + +// ClearSort clears the value of the "sort" field. +func (u *PermissionUpsert) ClearSort() *PermissionUpsert { + u.SetNull(permission.FieldSort) + return u +} + +// SetRemark sets the "remark" field. +func (u *PermissionUpsert) SetRemark(v string) *PermissionUpsert { + u.Set(permission.FieldRemark, v) + return u +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateRemark() *PermissionUpsert { + u.SetExcluded(permission.FieldRemark) + return u +} + +// ClearRemark clears the value of the "remark" field. +func (u *PermissionUpsert) ClearRemark() *PermissionUpsert { + u.SetNull(permission.FieldRemark) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *PermissionUpsert) SetCreatedAt(v int64) *PermissionUpsert { + u.Set(permission.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateCreatedAt() *PermissionUpsert { + u.SetExcluded(permission.FieldCreatedAt) + return u +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *PermissionUpsert) AddCreatedAt(v int64) *PermissionUpsert { + u.Add(permission.FieldCreatedAt, v) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *PermissionUpsert) SetUpdatedAt(v int64) *PermissionUpsert { + u.Set(permission.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *PermissionUpsert) UpdateUpdatedAt() *PermissionUpsert { + u.SetExcluded(permission.FieldUpdatedAt) + return u +} + +// AddUpdatedAt adds v to the "updated_at" field. +func (u *PermissionUpsert) AddUpdatedAt(v int64) *PermissionUpsert { + u.Add(permission.FieldUpdatedAt, v) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create. +// Using this option is equivalent to using: +// +// client.Permission.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *PermissionUpsertOne) UpdateNewValues() *PermissionUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Permission.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *PermissionUpsertOne) Ignore() *PermissionUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *PermissionUpsertOne) DoNothing() *PermissionUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the PermissionCreate.OnConflict +// documentation for more info. +func (u *PermissionUpsertOne) Update(set func(*PermissionUpsert)) *PermissionUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&PermissionUpsert{UpdateSet: update}) + })) + return u +} + +// SetCode sets the "code" field. +func (u *PermissionUpsertOne) SetCode(v string) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetCode(v) + }) +} + +// UpdateCode sets the "code" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateCode() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateCode() + }) +} + +// SetName sets the "name" field. +func (u *PermissionUpsertOne) SetName(v string) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateName() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateName() + }) +} + +// SetType sets the "type" field. +func (u *PermissionUpsertOne) SetType(v string) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetType(v) + }) +} + +// UpdateType sets the "type" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateType() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateType() + }) +} + +// SetPath sets the "path" field. +func (u *PermissionUpsertOne) SetPath(v string) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetPath(v) + }) +} + +// UpdatePath sets the "path" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdatePath() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdatePath() + }) +} + +// ClearPath clears the value of the "path" field. +func (u *PermissionUpsertOne) ClearPath() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.ClearPath() + }) +} + +// SetIcon sets the "icon" field. +func (u *PermissionUpsertOne) SetIcon(v string) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetIcon(v) + }) +} + +// UpdateIcon sets the "icon" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateIcon() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateIcon() + }) +} + +// ClearIcon clears the value of the "icon" field. +func (u *PermissionUpsertOne) ClearIcon() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.ClearIcon() + }) +} + +// SetSort sets the "sort" field. +func (u *PermissionUpsertOne) SetSort(v int) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetSort(v) + }) +} + +// AddSort adds v to the "sort" field. +func (u *PermissionUpsertOne) AddSort(v int) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.AddSort(v) + }) +} + +// UpdateSort sets the "sort" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateSort() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateSort() + }) +} + +// ClearSort clears the value of the "sort" field. +func (u *PermissionUpsertOne) ClearSort() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.ClearSort() + }) +} + +// SetRemark sets the "remark" field. +func (u *PermissionUpsertOne) SetRemark(v string) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetRemark(v) + }) +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateRemark() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateRemark() + }) +} + +// ClearRemark clears the value of the "remark" field. +func (u *PermissionUpsertOne) ClearRemark() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.ClearRemark() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *PermissionUpsertOne) SetCreatedAt(v int64) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *PermissionUpsertOne) AddCreatedAt(v int64) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateCreatedAt() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *PermissionUpsertOne) SetUpdatedAt(v int64) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.SetUpdatedAt(v) + }) +} + +// AddUpdatedAt adds v to the "updated_at" field. +func (u *PermissionUpsertOne) AddUpdatedAt(v int64) *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.AddUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *PermissionUpsertOne) UpdateUpdatedAt() *PermissionUpsertOne { + return u.Update(func(s *PermissionUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *PermissionUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for PermissionCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *PermissionUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *PermissionUpsertOne) ID(ctx context.Context) (id int, err error) { + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *PermissionUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// PermissionCreateBulk is the builder for creating many Permission entities in bulk. +type PermissionCreateBulk struct { + config + err error + builders []*PermissionCreate + conflict []sql.ConflictOption +} + +// Save creates the Permission entities in the database. +func (_c *PermissionCreateBulk) Save(ctx context.Context) ([]*Permission, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Permission, 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.(*PermissionMutation) + 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} + spec.OnConflict = _c.conflict + // 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 { + 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 *PermissionCreateBulk) SaveX(ctx context.Context) []*Permission { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *PermissionCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *PermissionCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Permission.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.PermissionUpsert) { +// SetCode(v+v). +// }). +// Exec(ctx) +func (_c *PermissionCreateBulk) OnConflict(opts ...sql.ConflictOption) *PermissionUpsertBulk { + _c.conflict = opts + return &PermissionUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Permission.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *PermissionCreateBulk) OnConflictColumns(columns ...string) *PermissionUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &PermissionUpsertBulk{ + create: _c, + } +} + +// PermissionUpsertBulk is the builder for "upsert"-ing +// a bulk of Permission nodes. +type PermissionUpsertBulk struct { + create *PermissionCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.Permission.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *PermissionUpsertBulk) UpdateNewValues() *PermissionUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Permission.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *PermissionUpsertBulk) Ignore() *PermissionUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *PermissionUpsertBulk) DoNothing() *PermissionUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the PermissionCreateBulk.OnConflict +// documentation for more info. +func (u *PermissionUpsertBulk) Update(set func(*PermissionUpsert)) *PermissionUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&PermissionUpsert{UpdateSet: update}) + })) + return u +} + +// SetCode sets the "code" field. +func (u *PermissionUpsertBulk) SetCode(v string) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetCode(v) + }) +} + +// UpdateCode sets the "code" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateCode() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateCode() + }) +} + +// SetName sets the "name" field. +func (u *PermissionUpsertBulk) SetName(v string) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateName() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateName() + }) +} + +// SetType sets the "type" field. +func (u *PermissionUpsertBulk) SetType(v string) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetType(v) + }) +} + +// UpdateType sets the "type" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateType() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateType() + }) +} + +// SetPath sets the "path" field. +func (u *PermissionUpsertBulk) SetPath(v string) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetPath(v) + }) +} + +// UpdatePath sets the "path" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdatePath() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdatePath() + }) +} + +// ClearPath clears the value of the "path" field. +func (u *PermissionUpsertBulk) ClearPath() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.ClearPath() + }) +} + +// SetIcon sets the "icon" field. +func (u *PermissionUpsertBulk) SetIcon(v string) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetIcon(v) + }) +} + +// UpdateIcon sets the "icon" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateIcon() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateIcon() + }) +} + +// ClearIcon clears the value of the "icon" field. +func (u *PermissionUpsertBulk) ClearIcon() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.ClearIcon() + }) +} + +// SetSort sets the "sort" field. +func (u *PermissionUpsertBulk) SetSort(v int) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetSort(v) + }) +} + +// AddSort adds v to the "sort" field. +func (u *PermissionUpsertBulk) AddSort(v int) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.AddSort(v) + }) +} + +// UpdateSort sets the "sort" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateSort() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateSort() + }) +} + +// ClearSort clears the value of the "sort" field. +func (u *PermissionUpsertBulk) ClearSort() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.ClearSort() + }) +} + +// SetRemark sets the "remark" field. +func (u *PermissionUpsertBulk) SetRemark(v string) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetRemark(v) + }) +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateRemark() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateRemark() + }) +} + +// ClearRemark clears the value of the "remark" field. +func (u *PermissionUpsertBulk) ClearRemark() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.ClearRemark() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *PermissionUpsertBulk) SetCreatedAt(v int64) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *PermissionUpsertBulk) AddCreatedAt(v int64) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateCreatedAt() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *PermissionUpsertBulk) SetUpdatedAt(v int64) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.SetUpdatedAt(v) + }) +} + +// AddUpdatedAt adds v to the "updated_at" field. +func (u *PermissionUpsertBulk) AddUpdatedAt(v int64) *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.AddUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *PermissionUpsertBulk) UpdateUpdatedAt() *PermissionUpsertBulk { + return u.Update(func(s *PermissionUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *PermissionUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the PermissionCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for PermissionCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *PermissionUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_wms/ent/packagebox_delete.go b/bj_power_wms/ent/permission_delete.go similarity index 54% rename from bj_power_wms/ent/packagebox_delete.go rename to bj_power_wms/ent/permission_delete.go index db69027..010a3d0 100644 --- a/bj_power_wms/ent/packagebox_delete.go +++ b/bj_power_wms/ent/permission_delete.go @@ -3,7 +3,7 @@ package ent import ( - "bj_power_wms/ent/packagebox" + "bj_power_wms/ent/permission" "bj_power_wms/ent/predicate" "context" @@ -12,26 +12,26 @@ import ( "entgo.io/ent/schema/field" ) -// PackageBoxDelete is the builder for deleting a PackageBox entity. -type PackageBoxDelete struct { +// PermissionDelete is the builder for deleting a Permission entity. +type PermissionDelete struct { config hooks []Hook - mutation *PackageBoxMutation + mutation *PermissionMutation } -// Where appends a list predicates to the PackageBoxDelete builder. -func (_d *PackageBoxDelete) Where(ps ...predicate.PackageBox) *PackageBoxDelete { +// Where appends a list predicates to the PermissionDelete builder. +func (_d *PermissionDelete) Where(ps ...predicate.Permission) *PermissionDelete { _d.mutation.Where(ps...) return _d } // Exec executes the deletion query and returns how many vertices were deleted. -func (_d *PackageBoxDelete) Exec(ctx context.Context) (int, error) { +func (_d *PermissionDelete) Exec(ctx context.Context) (int, error) { return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) } // ExecX is like Exec, but panics if an error occurs. -func (_d *PackageBoxDelete) ExecX(ctx context.Context) int { +func (_d *PermissionDelete) ExecX(ctx context.Context) int { n, err := _d.Exec(ctx) if err != nil { panic(err) @@ -39,8 +39,8 @@ func (_d *PackageBoxDelete) ExecX(ctx context.Context) int { return n } -func (_d *PackageBoxDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(packagebox.Table, sqlgraph.NewFieldSpec(packagebox.FieldID, field.TypeInt)) +func (_d *PermissionDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(permission.Table, sqlgraph.NewFieldSpec(permission.FieldID, field.TypeInt)) if ps := _d.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -56,32 +56,32 @@ func (_d *PackageBoxDelete) sqlExec(ctx context.Context) (int, error) { return affected, err } -// PackageBoxDeleteOne is the builder for deleting a single PackageBox entity. -type PackageBoxDeleteOne struct { - _d *PackageBoxDelete +// PermissionDeleteOne is the builder for deleting a single Permission entity. +type PermissionDeleteOne struct { + _d *PermissionDelete } -// Where appends a list predicates to the PackageBoxDelete builder. -func (_d *PackageBoxDeleteOne) Where(ps ...predicate.PackageBox) *PackageBoxDeleteOne { +// Where appends a list predicates to the PermissionDelete builder. +func (_d *PermissionDeleteOne) Where(ps ...predicate.Permission) *PermissionDeleteOne { _d._d.mutation.Where(ps...) return _d } // Exec executes the deletion query. -func (_d *PackageBoxDeleteOne) Exec(ctx context.Context) error { +func (_d *PermissionDeleteOne) Exec(ctx context.Context) error { n, err := _d._d.Exec(ctx) switch { case err != nil: return err case n == 0: - return &NotFoundError{packagebox.Label} + return &NotFoundError{permission.Label} default: return nil } } // ExecX is like Exec, but panics if an error occurs. -func (_d *PackageBoxDeleteOne) ExecX(ctx context.Context) { +func (_d *PermissionDeleteOne) ExecX(ctx context.Context) { if err := _d.Exec(ctx); err != nil { panic(err) } diff --git a/bj_power_wms/ent/packagebox_query.go b/bj_power_wms/ent/permission_query.go similarity index 63% rename from bj_power_wms/ent/packagebox_query.go rename to bj_power_wms/ent/permission_query.go index f686723..5aaf021 100644 --- a/bj_power_wms/ent/packagebox_query.go +++ b/bj_power_wms/ent/permission_query.go @@ -3,7 +3,7 @@ package ent import ( - "bj_power_wms/ent/packagebox" + "bj_power_wms/ent/permission" "bj_power_wms/ent/predicate" "context" "fmt" @@ -15,64 +15,64 @@ import ( "entgo.io/ent/schema/field" ) -// PackageBoxQuery is the builder for querying PackageBox entities. -type PackageBoxQuery struct { +// PermissionQuery is the builder for querying Permission entities. +type PermissionQuery struct { config ctx *QueryContext - order []packagebox.OrderOption + order []permission.OrderOption inters []Interceptor - predicates []predicate.PackageBox + predicates []predicate.Permission // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the PackageBoxQuery builder. -func (_q *PackageBoxQuery) Where(ps ...predicate.PackageBox) *PackageBoxQuery { +// Where adds a new predicate for the PermissionQuery builder. +func (_q *PermissionQuery) Where(ps ...predicate.Permission) *PermissionQuery { _q.predicates = append(_q.predicates, ps...) return _q } // Limit the number of records to be returned by this query. -func (_q *PackageBoxQuery) Limit(limit int) *PackageBoxQuery { +func (_q *PermissionQuery) Limit(limit int) *PermissionQuery { _q.ctx.Limit = &limit return _q } // Offset to start from. -func (_q *PackageBoxQuery) Offset(offset int) *PackageBoxQuery { +func (_q *PermissionQuery) Offset(offset int) *PermissionQuery { _q.ctx.Offset = &offset return _q } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. -func (_q *PackageBoxQuery) Unique(unique bool) *PackageBoxQuery { +func (_q *PermissionQuery) Unique(unique bool) *PermissionQuery { _q.ctx.Unique = &unique return _q } // Order specifies how the records should be ordered. -func (_q *PackageBoxQuery) Order(o ...packagebox.OrderOption) *PackageBoxQuery { +func (_q *PermissionQuery) Order(o ...permission.OrderOption) *PermissionQuery { _q.order = append(_q.order, o...) return _q } -// First returns the first PackageBox entity from the query. -// Returns a *NotFoundError when no PackageBox was found. -func (_q *PackageBoxQuery) First(ctx context.Context) (*PackageBox, error) { +// First returns the first Permission entity from the query. +// Returns a *NotFoundError when no Permission was found. +func (_q *PermissionQuery) First(ctx context.Context) (*Permission, error) { nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } if len(nodes) == 0 { - return nil, &NotFoundError{packagebox.Label} + return nil, &NotFoundError{permission.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. -func (_q *PackageBoxQuery) FirstX(ctx context.Context) *PackageBox { +func (_q *PermissionQuery) FirstX(ctx context.Context) *Permission { node, err := _q.First(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -80,22 +80,22 @@ func (_q *PackageBoxQuery) FirstX(ctx context.Context) *PackageBox { return node } -// FirstID returns the first PackageBox ID from the query. -// Returns a *NotFoundError when no PackageBox ID was found. -func (_q *PackageBoxQuery) FirstID(ctx context.Context) (id int, err error) { +// FirstID returns the first Permission ID from the query. +// Returns a *NotFoundError when no Permission ID was found. +func (_q *PermissionQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { - err = &NotFoundError{packagebox.Label} + err = &NotFoundError{permission.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. -func (_q *PackageBoxQuery) FirstIDX(ctx context.Context) int { +func (_q *PermissionQuery) FirstIDX(ctx context.Context) int { id, err := _q.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -103,10 +103,10 @@ func (_q *PackageBoxQuery) FirstIDX(ctx context.Context) int { return id } -// Only returns a single PackageBox entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one PackageBox entity is found. -// Returns a *NotFoundError when no PackageBox entities are found. -func (_q *PackageBoxQuery) Only(ctx context.Context) (*PackageBox, error) { +// Only returns a single Permission entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Permission entity is found. +// Returns a *NotFoundError when no Permission entities are found. +func (_q *PermissionQuery) Only(ctx context.Context) (*Permission, error) { nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) if err != nil { return nil, err @@ -115,14 +115,14 @@ func (_q *PackageBoxQuery) Only(ctx context.Context) (*PackageBox, error) { case 1: return nodes[0], nil case 0: - return nil, &NotFoundError{packagebox.Label} + return nil, &NotFoundError{permission.Label} default: - return nil, &NotSingularError{packagebox.Label} + return nil, &NotSingularError{permission.Label} } } // OnlyX is like Only, but panics if an error occurs. -func (_q *PackageBoxQuery) OnlyX(ctx context.Context) *PackageBox { +func (_q *PermissionQuery) OnlyX(ctx context.Context) *Permission { node, err := _q.Only(ctx) if err != nil { panic(err) @@ -130,10 +130,10 @@ func (_q *PackageBoxQuery) OnlyX(ctx context.Context) *PackageBox { return node } -// OnlyID is like Only, but returns the only PackageBox ID in the query. -// Returns a *NotSingularError when more than one PackageBox ID is found. +// OnlyID is like Only, but returns the only Permission ID in the query. +// Returns a *NotSingularError when more than one Permission ID is found. // Returns a *NotFoundError when no entities are found. -func (_q *PackageBoxQuery) OnlyID(ctx context.Context) (id int, err error) { +func (_q *PermissionQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { return @@ -142,15 +142,15 @@ func (_q *PackageBoxQuery) OnlyID(ctx context.Context) (id int, err error) { case 1: id = ids[0] case 0: - err = &NotFoundError{packagebox.Label} + err = &NotFoundError{permission.Label} default: - err = &NotSingularError{packagebox.Label} + err = &NotSingularError{permission.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *PackageBoxQuery) OnlyIDX(ctx context.Context) int { +func (_q *PermissionQuery) OnlyIDX(ctx context.Context) int { id, err := _q.OnlyID(ctx) if err != nil { panic(err) @@ -158,18 +158,18 @@ func (_q *PackageBoxQuery) OnlyIDX(ctx context.Context) int { return id } -// All executes the query and returns a list of PackageBoxes. -func (_q *PackageBoxQuery) All(ctx context.Context) ([]*PackageBox, error) { +// All executes the query and returns a list of Permissions. +func (_q *PermissionQuery) All(ctx context.Context) ([]*Permission, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) if err := _q.prepareQuery(ctx); err != nil { return nil, err } - qr := querierAll[[]*PackageBox, *PackageBoxQuery]() - return withInterceptors[[]*PackageBox](ctx, _q, qr, _q.inters) + qr := querierAll[[]*Permission, *PermissionQuery]() + return withInterceptors[[]*Permission](ctx, _q, qr, _q.inters) } // AllX is like All, but panics if an error occurs. -func (_q *PackageBoxQuery) AllX(ctx context.Context) []*PackageBox { +func (_q *PermissionQuery) AllX(ctx context.Context) []*Permission { nodes, err := _q.All(ctx) if err != nil { panic(err) @@ -177,20 +177,20 @@ func (_q *PackageBoxQuery) AllX(ctx context.Context) []*PackageBox { return nodes } -// IDs executes the query and returns a list of PackageBox IDs. -func (_q *PackageBoxQuery) IDs(ctx context.Context) (ids []int, err error) { +// IDs executes the query and returns a list of Permission IDs. +func (_q *PermissionQuery) IDs(ctx context.Context) (ids []int, err error) { if _q.ctx.Unique == nil && _q.path != nil { _q.Unique(true) } ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(packagebox.FieldID).Scan(ctx, &ids); err != nil { + if err = _q.Select(permission.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. -func (_q *PackageBoxQuery) IDsX(ctx context.Context) []int { +func (_q *PermissionQuery) IDsX(ctx context.Context) []int { ids, err := _q.IDs(ctx) if err != nil { panic(err) @@ -199,16 +199,16 @@ func (_q *PackageBoxQuery) IDsX(ctx context.Context) []int { } // Count returns the count of the given query. -func (_q *PackageBoxQuery) Count(ctx context.Context) (int, error) { +func (_q *PermissionQuery) Count(ctx context.Context) (int, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) if err := _q.prepareQuery(ctx); err != nil { return 0, err } - return withInterceptors[int](ctx, _q, querierCount[*PackageBoxQuery](), _q.inters) + return withInterceptors[int](ctx, _q, querierCount[*PermissionQuery](), _q.inters) } // CountX is like Count, but panics if an error occurs. -func (_q *PackageBoxQuery) CountX(ctx context.Context) int { +func (_q *PermissionQuery) CountX(ctx context.Context) int { count, err := _q.Count(ctx) if err != nil { panic(err) @@ -217,7 +217,7 @@ func (_q *PackageBoxQuery) CountX(ctx context.Context) int { } // Exist returns true if the query has elements in the graph. -func (_q *PackageBoxQuery) Exist(ctx context.Context) (bool, error) { +func (_q *PermissionQuery) Exist(ctx context.Context) (bool, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) switch _, err := _q.FirstID(ctx); { case IsNotFound(err): @@ -230,7 +230,7 @@ func (_q *PackageBoxQuery) Exist(ctx context.Context) (bool, error) { } // ExistX is like Exist, but panics if an error occurs. -func (_q *PackageBoxQuery) ExistX(ctx context.Context) bool { +func (_q *PermissionQuery) ExistX(ctx context.Context) bool { exist, err := _q.Exist(ctx) if err != nil { panic(err) @@ -238,18 +238,18 @@ func (_q *PackageBoxQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the PackageBoxQuery builder, including all associated steps. It can be +// Clone returns a duplicate of the PermissionQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. -func (_q *PackageBoxQuery) Clone() *PackageBoxQuery { +func (_q *PermissionQuery) Clone() *PermissionQuery { if _q == nil { return nil } - return &PackageBoxQuery{ + return &PermissionQuery{ config: _q.config, ctx: _q.ctx.Clone(), - order: append([]packagebox.OrderOption{}, _q.order...), + order: append([]permission.OrderOption{}, _q.order...), inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.PackageBox{}, _q.predicates...), + predicates: append([]predicate.Permission{}, _q.predicates...), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, @@ -262,19 +262,19 @@ func (_q *PackageBoxQuery) Clone() *PackageBoxQuery { // Example: // // var v []struct { -// BoxNo string `json:"boxNo,omitempty"` +// Code string `json:"code,omitempty"` // Count int `json:"count,omitempty"` // } // -// client.PackageBox.Query(). -// GroupBy(packagebox.FieldBoxNo). +// client.Permission.Query(). +// GroupBy(permission.FieldCode). // Aggregate(ent.Count()). // Scan(ctx, &v) -func (_q *PackageBoxQuery) GroupBy(field string, fields ...string) *PackageBoxGroupBy { +func (_q *PermissionQuery) GroupBy(field string, fields ...string) *PermissionGroupBy { _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &PackageBoxGroupBy{build: _q} + grbuild := &PermissionGroupBy{build: _q} grbuild.flds = &_q.ctx.Fields - grbuild.label = packagebox.Label + grbuild.label = permission.Label grbuild.scan = grbuild.Scan return grbuild } @@ -285,26 +285,26 @@ func (_q *PackageBoxQuery) GroupBy(field string, fields ...string) *PackageBoxGr // Example: // // var v []struct { -// BoxNo string `json:"boxNo,omitempty"` +// Code string `json:"code,omitempty"` // } // -// client.PackageBox.Query(). -// Select(packagebox.FieldBoxNo). +// client.Permission.Query(). +// Select(permission.FieldCode). // Scan(ctx, &v) -func (_q *PackageBoxQuery) Select(fields ...string) *PackageBoxSelect { +func (_q *PermissionQuery) Select(fields ...string) *PermissionSelect { _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &PackageBoxSelect{PackageBoxQuery: _q} - sbuild.label = packagebox.Label + sbuild := &PermissionSelect{PermissionQuery: _q} + sbuild.label = permission.Label sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan return sbuild } -// Aggregate returns a PackageBoxSelect configured with the given aggregations. -func (_q *PackageBoxQuery) Aggregate(fns ...AggregateFunc) *PackageBoxSelect { +// Aggregate returns a PermissionSelect configured with the given aggregations. +func (_q *PermissionQuery) Aggregate(fns ...AggregateFunc) *PermissionSelect { return _q.Select().Aggregate(fns...) } -func (_q *PackageBoxQuery) prepareQuery(ctx context.Context) error { +func (_q *PermissionQuery) prepareQuery(ctx context.Context) error { for _, inter := range _q.inters { if inter == nil { return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") @@ -316,7 +316,7 @@ func (_q *PackageBoxQuery) prepareQuery(ctx context.Context) error { } } for _, f := range _q.ctx.Fields { - if !packagebox.ValidColumn(f) { + if !permission.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } @@ -330,16 +330,16 @@ func (_q *PackageBoxQuery) prepareQuery(ctx context.Context) error { return nil } -func (_q *PackageBoxQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PackageBox, error) { +func (_q *PermissionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Permission, error) { var ( - nodes = []*PackageBox{} + nodes = []*Permission{} _spec = _q.querySpec() ) _spec.ScanValues = func(columns []string) ([]any, error) { - return (*PackageBox).scanValues(nil, columns) + return (*Permission).scanValues(nil, columns) } _spec.Assign = func(columns []string, values []any) error { - node := &PackageBox{config: _q.config} + node := &Permission{config: _q.config} nodes = append(nodes, node) return node.assignValues(columns, values) } @@ -355,7 +355,7 @@ func (_q *PackageBoxQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*P return nodes, nil } -func (_q *PackageBoxQuery) sqlCount(ctx context.Context) (int, error) { +func (_q *PermissionQuery) sqlCount(ctx context.Context) (int, error) { _spec := _q.querySpec() _spec.Node.Columns = _q.ctx.Fields if len(_q.ctx.Fields) > 0 { @@ -364,8 +364,8 @@ func (_q *PackageBoxQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, _q.driver, _spec) } -func (_q *PackageBoxQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(packagebox.Table, packagebox.Columns, sqlgraph.NewFieldSpec(packagebox.FieldID, field.TypeInt)) +func (_q *PermissionQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(permission.Table, permission.Columns, sqlgraph.NewFieldSpec(permission.FieldID, field.TypeInt)) _spec.From = _q.sql if unique := _q.ctx.Unique; unique != nil { _spec.Unique = *unique @@ -374,9 +374,9 @@ func (_q *PackageBoxQuery) querySpec() *sqlgraph.QuerySpec { } if fields := _q.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, packagebox.FieldID) + _spec.Node.Columns = append(_spec.Node.Columns, permission.FieldID) for i := range fields { - if fields[i] != packagebox.FieldID { + if fields[i] != permission.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } @@ -404,12 +404,12 @@ func (_q *PackageBoxQuery) querySpec() *sqlgraph.QuerySpec { return _spec } -func (_q *PackageBoxQuery) sqlQuery(ctx context.Context) *sql.Selector { +func (_q *PermissionQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(packagebox.Table) + t1 := builder.Table(permission.Table) columns := _q.ctx.Fields if len(columns) == 0 { - columns = packagebox.Columns + columns = permission.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if _q.sql != nil { @@ -436,28 +436,28 @@ func (_q *PackageBoxQuery) sqlQuery(ctx context.Context) *sql.Selector { return selector } -// PackageBoxGroupBy is the group-by builder for PackageBox entities. -type PackageBoxGroupBy struct { +// PermissionGroupBy is the group-by builder for Permission entities. +type PermissionGroupBy struct { selector - build *PackageBoxQuery + build *PermissionQuery } // Aggregate adds the given aggregation functions to the group-by query. -func (_g *PackageBoxGroupBy) Aggregate(fns ...AggregateFunc) *PackageBoxGroupBy { +func (_g *PermissionGroupBy) Aggregate(fns ...AggregateFunc) *PermissionGroupBy { _g.fns = append(_g.fns, fns...) return _g } // Scan applies the selector query and scans the result into the given value. -func (_g *PackageBoxGroupBy) Scan(ctx context.Context, v any) error { +func (_g *PermissionGroupBy) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) if err := _g.build.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*PackageBoxQuery, *PackageBoxGroupBy](ctx, _g.build, _g, _g.build.inters, v) + return scanWithInterceptors[*PermissionQuery, *PermissionGroupBy](ctx, _g.build, _g, _g.build.inters, v) } -func (_g *PackageBoxGroupBy) sqlScan(ctx context.Context, root *PackageBoxQuery, v any) error { +func (_g *PermissionGroupBy) sqlScan(ctx context.Context, root *PermissionQuery, v any) error { selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(_g.fns)) for _, fn := range _g.fns { @@ -484,28 +484,28 @@ func (_g *PackageBoxGroupBy) sqlScan(ctx context.Context, root *PackageBoxQuery, return sql.ScanSlice(rows, v) } -// PackageBoxSelect is the builder for selecting fields of PackageBox entities. -type PackageBoxSelect struct { - *PackageBoxQuery +// PermissionSelect is the builder for selecting fields of Permission entities. +type PermissionSelect struct { + *PermissionQuery selector } // Aggregate adds the given aggregation functions to the selector query. -func (_s *PackageBoxSelect) Aggregate(fns ...AggregateFunc) *PackageBoxSelect { +func (_s *PermissionSelect) Aggregate(fns ...AggregateFunc) *PermissionSelect { _s.fns = append(_s.fns, fns...) return _s } // Scan applies the selector query and scans the result into the given value. -func (_s *PackageBoxSelect) Scan(ctx context.Context, v any) error { +func (_s *PermissionSelect) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) if err := _s.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*PackageBoxQuery, *PackageBoxSelect](ctx, _s.PackageBoxQuery, _s, _s.inters, v) + return scanWithInterceptors[*PermissionQuery, *PermissionSelect](ctx, _s.PermissionQuery, _s, _s.inters, v) } -func (_s *PackageBoxSelect) sqlScan(ctx context.Context, root *PackageBoxQuery, v any) error { +func (_s *PermissionSelect) sqlScan(ctx context.Context, root *PermissionQuery, v any) error { selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(_s.fns)) for _, fn := range _s.fns { diff --git a/bj_power_wms/ent/permission_update.go b/bj_power_wms/ent/permission_update.go new file mode 100644 index 0000000..34394ce --- /dev/null +++ b/bj_power_wms/ent/permission_update.go @@ -0,0 +1,689 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/permission" + "bj_power_wms/ent/predicate" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// PermissionUpdate is the builder for updating Permission entities. +type PermissionUpdate struct { + config + hooks []Hook + mutation *PermissionMutation +} + +// Where appends a list predicates to the PermissionUpdate builder. +func (_u *PermissionUpdate) Where(ps ...predicate.Permission) *PermissionUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetCode sets the "code" field. +func (_u *PermissionUpdate) SetCode(v string) *PermissionUpdate { + _u.mutation.SetCode(v) + return _u +} + +// SetNillableCode sets the "code" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableCode(v *string) *PermissionUpdate { + if v != nil { + _u.SetCode(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *PermissionUpdate) SetName(v string) *PermissionUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableName(v *string) *PermissionUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetType sets the "type" field. +func (_u *PermissionUpdate) SetType(v string) *PermissionUpdate { + _u.mutation.SetType(v) + return _u +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableType(v *string) *PermissionUpdate { + if v != nil { + _u.SetType(*v) + } + return _u +} + +// SetPath sets the "path" field. +func (_u *PermissionUpdate) SetPath(v string) *PermissionUpdate { + _u.mutation.SetPath(v) + return _u +} + +// SetNillablePath sets the "path" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillablePath(v *string) *PermissionUpdate { + if v != nil { + _u.SetPath(*v) + } + return _u +} + +// ClearPath clears the value of the "path" field. +func (_u *PermissionUpdate) ClearPath() *PermissionUpdate { + _u.mutation.ClearPath() + return _u +} + +// SetIcon sets the "icon" field. +func (_u *PermissionUpdate) SetIcon(v string) *PermissionUpdate { + _u.mutation.SetIcon(v) + return _u +} + +// SetNillableIcon sets the "icon" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableIcon(v *string) *PermissionUpdate { + if v != nil { + _u.SetIcon(*v) + } + return _u +} + +// ClearIcon clears the value of the "icon" field. +func (_u *PermissionUpdate) ClearIcon() *PermissionUpdate { + _u.mutation.ClearIcon() + return _u +} + +// SetSort sets the "sort" field. +func (_u *PermissionUpdate) SetSort(v int) *PermissionUpdate { + _u.mutation.ResetSort() + _u.mutation.SetSort(v) + return _u +} + +// SetNillableSort sets the "sort" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableSort(v *int) *PermissionUpdate { + if v != nil { + _u.SetSort(*v) + } + return _u +} + +// AddSort adds value to the "sort" field. +func (_u *PermissionUpdate) AddSort(v int) *PermissionUpdate { + _u.mutation.AddSort(v) + return _u +} + +// ClearSort clears the value of the "sort" field. +func (_u *PermissionUpdate) ClearSort() *PermissionUpdate { + _u.mutation.ClearSort() + return _u +} + +// SetRemark sets the "remark" field. +func (_u *PermissionUpdate) SetRemark(v string) *PermissionUpdate { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableRemark(v *string) *PermissionUpdate { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// ClearRemark clears the value of the "remark" field. +func (_u *PermissionUpdate) ClearRemark() *PermissionUpdate { + _u.mutation.ClearRemark() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *PermissionUpdate) SetCreatedAt(v int64) *PermissionUpdate { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableCreatedAt(v *int64) *PermissionUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *PermissionUpdate) AddCreatedAt(v int64) *PermissionUpdate { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *PermissionUpdate) SetUpdatedAt(v int64) *PermissionUpdate { + _u.mutation.ResetUpdatedAt() + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *PermissionUpdate) SetNillableUpdatedAt(v *int64) *PermissionUpdate { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// AddUpdatedAt adds value to the "updated_at" field. +func (_u *PermissionUpdate) AddUpdatedAt(v int64) *PermissionUpdate { + _u.mutation.AddUpdatedAt(v) + return _u +} + +// Mutation returns the PermissionMutation object of the builder. +func (_u *PermissionUpdate) Mutation() *PermissionMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *PermissionUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *PermissionUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *PermissionUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *PermissionUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *PermissionUpdate) check() error { + if v, ok := _u.mutation.Code(); ok { + if err := permission.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Permission.code": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := permission.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Permission.name": %w`, err)} + } + } + if v, ok := _u.mutation.GetType(); ok { + if err := permission.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Permission.type": %w`, err)} + } + } + if v, ok := _u.mutation.Path(); ok { + if err := permission.PathValidator(v); err != nil { + return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Permission.path": %w`, err)} + } + } + if v, ok := _u.mutation.Icon(); ok { + if err := permission.IconValidator(v); err != nil { + return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Permission.icon": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := permission.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Permission.remark": %w`, err)} + } + } + return nil +} + +func (_u *PermissionUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(permission.Table, permission.Columns, sqlgraph.NewFieldSpec(permission.FieldID, field.TypeInt)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Code(); ok { + _spec.SetField(permission.FieldCode, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(permission.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.GetType(); ok { + _spec.SetField(permission.FieldType, field.TypeString, value) + } + if value, ok := _u.mutation.Path(); ok { + _spec.SetField(permission.FieldPath, field.TypeString, value) + } + if _u.mutation.PathCleared() { + _spec.ClearField(permission.FieldPath, field.TypeString) + } + if value, ok := _u.mutation.Icon(); ok { + _spec.SetField(permission.FieldIcon, field.TypeString, value) + } + if _u.mutation.IconCleared() { + _spec.ClearField(permission.FieldIcon, field.TypeString) + } + if value, ok := _u.mutation.Sort(); ok { + _spec.SetField(permission.FieldSort, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedSort(); ok { + _spec.AddField(permission.FieldSort, field.TypeInt, value) + } + if _u.mutation.SortCleared() { + _spec.ClearField(permission.FieldSort, field.TypeInt) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(permission.FieldRemark, field.TypeString, value) + } + if _u.mutation.RemarkCleared() { + _spec.ClearField(permission.FieldRemark, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(permission.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(permission.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(permission.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedUpdatedAt(); ok { + _spec.AddField(permission.FieldUpdatedAt, field.TypeInt64, value) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{permission.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// PermissionUpdateOne is the builder for updating a single Permission entity. +type PermissionUpdateOne struct { + config + fields []string + hooks []Hook + mutation *PermissionMutation +} + +// SetCode sets the "code" field. +func (_u *PermissionUpdateOne) SetCode(v string) *PermissionUpdateOne { + _u.mutation.SetCode(v) + return _u +} + +// SetNillableCode sets the "code" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableCode(v *string) *PermissionUpdateOne { + if v != nil { + _u.SetCode(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *PermissionUpdateOne) SetName(v string) *PermissionUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableName(v *string) *PermissionUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetType sets the "type" field. +func (_u *PermissionUpdateOne) SetType(v string) *PermissionUpdateOne { + _u.mutation.SetType(v) + return _u +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableType(v *string) *PermissionUpdateOne { + if v != nil { + _u.SetType(*v) + } + return _u +} + +// SetPath sets the "path" field. +func (_u *PermissionUpdateOne) SetPath(v string) *PermissionUpdateOne { + _u.mutation.SetPath(v) + return _u +} + +// SetNillablePath sets the "path" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillablePath(v *string) *PermissionUpdateOne { + if v != nil { + _u.SetPath(*v) + } + return _u +} + +// ClearPath clears the value of the "path" field. +func (_u *PermissionUpdateOne) ClearPath() *PermissionUpdateOne { + _u.mutation.ClearPath() + return _u +} + +// SetIcon sets the "icon" field. +func (_u *PermissionUpdateOne) SetIcon(v string) *PermissionUpdateOne { + _u.mutation.SetIcon(v) + return _u +} + +// SetNillableIcon sets the "icon" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableIcon(v *string) *PermissionUpdateOne { + if v != nil { + _u.SetIcon(*v) + } + return _u +} + +// ClearIcon clears the value of the "icon" field. +func (_u *PermissionUpdateOne) ClearIcon() *PermissionUpdateOne { + _u.mutation.ClearIcon() + return _u +} + +// SetSort sets the "sort" field. +func (_u *PermissionUpdateOne) SetSort(v int) *PermissionUpdateOne { + _u.mutation.ResetSort() + _u.mutation.SetSort(v) + return _u +} + +// SetNillableSort sets the "sort" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableSort(v *int) *PermissionUpdateOne { + if v != nil { + _u.SetSort(*v) + } + return _u +} + +// AddSort adds value to the "sort" field. +func (_u *PermissionUpdateOne) AddSort(v int) *PermissionUpdateOne { + _u.mutation.AddSort(v) + return _u +} + +// ClearSort clears the value of the "sort" field. +func (_u *PermissionUpdateOne) ClearSort() *PermissionUpdateOne { + _u.mutation.ClearSort() + return _u +} + +// SetRemark sets the "remark" field. +func (_u *PermissionUpdateOne) SetRemark(v string) *PermissionUpdateOne { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableRemark(v *string) *PermissionUpdateOne { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// ClearRemark clears the value of the "remark" field. +func (_u *PermissionUpdateOne) ClearRemark() *PermissionUpdateOne { + _u.mutation.ClearRemark() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *PermissionUpdateOne) SetCreatedAt(v int64) *PermissionUpdateOne { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableCreatedAt(v *int64) *PermissionUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *PermissionUpdateOne) AddCreatedAt(v int64) *PermissionUpdateOne { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *PermissionUpdateOne) SetUpdatedAt(v int64) *PermissionUpdateOne { + _u.mutation.ResetUpdatedAt() + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *PermissionUpdateOne) SetNillableUpdatedAt(v *int64) *PermissionUpdateOne { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// AddUpdatedAt adds value to the "updated_at" field. +func (_u *PermissionUpdateOne) AddUpdatedAt(v int64) *PermissionUpdateOne { + _u.mutation.AddUpdatedAt(v) + return _u +} + +// Mutation returns the PermissionMutation object of the builder. +func (_u *PermissionUpdateOne) Mutation() *PermissionMutation { + return _u.mutation +} + +// Where appends a list predicates to the PermissionUpdate builder. +func (_u *PermissionUpdateOne) Where(ps ...predicate.Permission) *PermissionUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *PermissionUpdateOne) Select(field string, fields ...string) *PermissionUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Permission entity. +func (_u *PermissionUpdateOne) Save(ctx context.Context) (*Permission, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *PermissionUpdateOne) SaveX(ctx context.Context) *Permission { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *PermissionUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *PermissionUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *PermissionUpdateOne) check() error { + if v, ok := _u.mutation.Code(); ok { + if err := permission.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Permission.code": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := permission.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Permission.name": %w`, err)} + } + } + if v, ok := _u.mutation.GetType(); ok { + if err := permission.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Permission.type": %w`, err)} + } + } + if v, ok := _u.mutation.Path(); ok { + if err := permission.PathValidator(v); err != nil { + return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Permission.path": %w`, err)} + } + } + if v, ok := _u.mutation.Icon(); ok { + if err := permission.IconValidator(v); err != nil { + return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Permission.icon": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := permission.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Permission.remark": %w`, err)} + } + } + return nil +} + +func (_u *PermissionUpdateOne) sqlSave(ctx context.Context) (_node *Permission, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(permission.Table, permission.Columns, sqlgraph.NewFieldSpec(permission.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Permission.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, permission.FieldID) + for _, f := range fields { + if !permission.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != permission.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Code(); ok { + _spec.SetField(permission.FieldCode, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(permission.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.GetType(); ok { + _spec.SetField(permission.FieldType, field.TypeString, value) + } + if value, ok := _u.mutation.Path(); ok { + _spec.SetField(permission.FieldPath, field.TypeString, value) + } + if _u.mutation.PathCleared() { + _spec.ClearField(permission.FieldPath, field.TypeString) + } + if value, ok := _u.mutation.Icon(); ok { + _spec.SetField(permission.FieldIcon, field.TypeString, value) + } + if _u.mutation.IconCleared() { + _spec.ClearField(permission.FieldIcon, field.TypeString) + } + if value, ok := _u.mutation.Sort(); ok { + _spec.SetField(permission.FieldSort, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedSort(); ok { + _spec.AddField(permission.FieldSort, field.TypeInt, value) + } + if _u.mutation.SortCleared() { + _spec.ClearField(permission.FieldSort, field.TypeInt) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(permission.FieldRemark, field.TypeString, value) + } + if _u.mutation.RemarkCleared() { + _spec.ClearField(permission.FieldRemark, field.TypeString) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(permission.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(permission.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(permission.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedUpdatedAt(); ok { + _spec.AddField(permission.FieldUpdatedAt, field.TypeInt64, value) + } + _node = &Permission{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{permission.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/bj_power_wms/ent/predicate/predicate.go b/bj_power_wms/ent/predicate/predicate.go index 124afba..9091a51 100644 --- a/bj_power_wms/ent/predicate/predicate.go +++ b/bj_power_wms/ent/predicate/predicate.go @@ -33,8 +33,11 @@ type OutboundDetail func(*sql.Selector) // OutboundOrder is the predicate function for outboundorder builders. type OutboundOrder func(*sql.Selector) -// PackageBox is the predicate function for packagebox builders. -type PackageBox func(*sql.Selector) +// Permission is the predicate function for permission builders. +type Permission func(*sql.Selector) + +// Role is the predicate function for role builders. +type Role func(*sql.Selector) // SemiFinished is the predicate function for semifinished builders. type SemiFinished func(*sql.Selector) diff --git a/bj_power_wms/ent/role.go b/bj_power_wms/ent/role.go new file mode 100644 index 0000000..73304dc --- /dev/null +++ b/bj_power_wms/ent/role.go @@ -0,0 +1,163 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/role" + "encoding/json" + "fmt" + "strings" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// Role is the model entity for the Role schema. +type Role struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 角色名称 + Name string `json:"name,omitempty"` + // 角色编码,如 admin/operator/inspector + Code string `json:"code,omitempty"` + // 备注 + Remark string `json:"remark,omitempty"` + // 权限编码列表 + PermissionCodes []string `json:"permissionCodes,omitempty"` + // 创建时间 + CreatedAt int64 `json:"createdAt,omitempty"` + // 更新时间 + UpdatedAt int64 `json:"updatedAt,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Role) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case role.FieldPermissionCodes: + values[i] = new([]byte) + case role.FieldID, role.FieldCreatedAt, role.FieldUpdatedAt: + values[i] = new(sql.NullInt64) + case role.FieldName, role.FieldCode, role.FieldRemark: + values[i] = new(sql.NullString) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Role fields. +func (_m *Role) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case role.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + _m.ID = int(value.Int64) + case role.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case role.FieldCode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field code", values[i]) + } else if value.Valid { + _m.Code = value.String + } + case role.FieldRemark: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field remark", values[i]) + } else if value.Valid { + _m.Remark = value.String + } + case role.FieldPermissionCodes: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field permission_codes", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.PermissionCodes); err != nil { + return fmt.Errorf("unmarshal field permission_codes: %w", err) + } + } + case role.FieldCreatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Int64 + } + case role.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Int64 + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the Role. +// This includes values selected through modifiers, order, etc. +func (_m *Role) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this Role. +// Note that you need to call Role.Unwrap() before calling this method if this Role +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *Role) Update() *RoleUpdateOne { + return NewRoleClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the Role entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *Role) Unwrap() *Role { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: Role is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *Role) String() string { + var builder strings.Builder + builder.WriteString("Role(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("code=") + builder.WriteString(_m.Code) + builder.WriteString(", ") + builder.WriteString("remark=") + builder.WriteString(_m.Remark) + builder.WriteString(", ") + builder.WriteString("permission_codes=") + builder.WriteString(fmt.Sprintf("%v", _m.PermissionCodes)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(fmt.Sprintf("%v", _m.CreatedAt)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(fmt.Sprintf("%v", _m.UpdatedAt)) + builder.WriteByte(')') + return builder.String() +} + +// Roles is a parsable slice of Role. +type Roles []*Role diff --git a/bj_power_wms/ent/role/role.go b/bj_power_wms/ent/role/role.go new file mode 100644 index 0000000..1a988d6 --- /dev/null +++ b/bj_power_wms/ent/role/role.go @@ -0,0 +1,97 @@ +// Code generated by ent, DO NOT EDIT. + +package role + +import ( + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the role type in the database. + Label = "role" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldCode holds the string denoting the code field in the database. + FieldCode = "code" + // FieldRemark holds the string denoting the remark field in the database. + FieldRemark = "remark" + // FieldPermissionCodes holds the string denoting the permission_codes field in the database. + FieldPermissionCodes = "permission_codes" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // Table holds the table name of the role in the database. + Table = "roles" +) + +// Columns holds all SQL columns for role fields. +var Columns = []string{ + FieldID, + FieldName, + FieldCode, + FieldRemark, + FieldPermissionCodes, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // CodeValidator is a validator for the "code" field. It is called by the builders before save. + CodeValidator func(string) error + // DefaultRemark holds the default value on creation for the "remark" field. + DefaultRemark string + // RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + RemarkValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() int64 + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() int64 +) + +// OrderOption defines the ordering options for the Role queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByCode orders the results by the code field. +func ByCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCode, opts...).ToFunc() +} + +// ByRemark orders the results by the remark field. +func ByRemark(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRemark, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} diff --git a/bj_power_wms/ent/role/where.go b/bj_power_wms/ent/role/where.go new file mode 100644 index 0000000..ad367ca --- /dev/null +++ b/bj_power_wms/ent/role/where.go @@ -0,0 +1,389 @@ +// Code generated by ent, DO NOT EDIT. + +package role + +import ( + "bj_power_wms/ent/predicate" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.Role { + return predicate.Role(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.Role { + return predicate.Role(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.Role { + return predicate.Role(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.Role { + return predicate.Role(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.Role { + return predicate.Role(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.Role { + return predicate.Role(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.Role { + return predicate.Role(sql.FieldLTE(FieldID, id)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldName, v)) +} + +// Code applies equality check predicate on the "code" field. It's identical to CodeEQ. +func Code(v string) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldCode, v)) +} + +// Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. +func Remark(v string) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldRemark, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v int64) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v int64) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Role { + return predicate.Role(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Role { + return predicate.Role(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Role { + return predicate.Role(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Role { + return predicate.Role(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Role { + return predicate.Role(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Role { + return predicate.Role(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Role { + return predicate.Role(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Role { + return predicate.Role(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Role { + return predicate.Role(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Role { + return predicate.Role(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Role { + return predicate.Role(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Role { + return predicate.Role(sql.FieldContainsFold(FieldName, v)) +} + +// CodeEQ applies the EQ predicate on the "code" field. +func CodeEQ(v string) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldCode, v)) +} + +// CodeNEQ applies the NEQ predicate on the "code" field. +func CodeNEQ(v string) predicate.Role { + return predicate.Role(sql.FieldNEQ(FieldCode, v)) +} + +// CodeIn applies the In predicate on the "code" field. +func CodeIn(vs ...string) predicate.Role { + return predicate.Role(sql.FieldIn(FieldCode, vs...)) +} + +// CodeNotIn applies the NotIn predicate on the "code" field. +func CodeNotIn(vs ...string) predicate.Role { + return predicate.Role(sql.FieldNotIn(FieldCode, vs...)) +} + +// CodeGT applies the GT predicate on the "code" field. +func CodeGT(v string) predicate.Role { + return predicate.Role(sql.FieldGT(FieldCode, v)) +} + +// CodeGTE applies the GTE predicate on the "code" field. +func CodeGTE(v string) predicate.Role { + return predicate.Role(sql.FieldGTE(FieldCode, v)) +} + +// CodeLT applies the LT predicate on the "code" field. +func CodeLT(v string) predicate.Role { + return predicate.Role(sql.FieldLT(FieldCode, v)) +} + +// CodeLTE applies the LTE predicate on the "code" field. +func CodeLTE(v string) predicate.Role { + return predicate.Role(sql.FieldLTE(FieldCode, v)) +} + +// CodeContains applies the Contains predicate on the "code" field. +func CodeContains(v string) predicate.Role { + return predicate.Role(sql.FieldContains(FieldCode, v)) +} + +// CodeHasPrefix applies the HasPrefix predicate on the "code" field. +func CodeHasPrefix(v string) predicate.Role { + return predicate.Role(sql.FieldHasPrefix(FieldCode, v)) +} + +// CodeHasSuffix applies the HasSuffix predicate on the "code" field. +func CodeHasSuffix(v string) predicate.Role { + return predicate.Role(sql.FieldHasSuffix(FieldCode, v)) +} + +// CodeEqualFold applies the EqualFold predicate on the "code" field. +func CodeEqualFold(v string) predicate.Role { + return predicate.Role(sql.FieldEqualFold(FieldCode, v)) +} + +// CodeContainsFold applies the ContainsFold predicate on the "code" field. +func CodeContainsFold(v string) predicate.Role { + return predicate.Role(sql.FieldContainsFold(FieldCode, v)) +} + +// RemarkEQ applies the EQ predicate on the "remark" field. +func RemarkEQ(v string) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldRemark, v)) +} + +// RemarkNEQ applies the NEQ predicate on the "remark" field. +func RemarkNEQ(v string) predicate.Role { + return predicate.Role(sql.FieldNEQ(FieldRemark, v)) +} + +// RemarkIn applies the In predicate on the "remark" field. +func RemarkIn(vs ...string) predicate.Role { + return predicate.Role(sql.FieldIn(FieldRemark, vs...)) +} + +// RemarkNotIn applies the NotIn predicate on the "remark" field. +func RemarkNotIn(vs ...string) predicate.Role { + return predicate.Role(sql.FieldNotIn(FieldRemark, vs...)) +} + +// RemarkGT applies the GT predicate on the "remark" field. +func RemarkGT(v string) predicate.Role { + return predicate.Role(sql.FieldGT(FieldRemark, v)) +} + +// RemarkGTE applies the GTE predicate on the "remark" field. +func RemarkGTE(v string) predicate.Role { + return predicate.Role(sql.FieldGTE(FieldRemark, v)) +} + +// RemarkLT applies the LT predicate on the "remark" field. +func RemarkLT(v string) predicate.Role { + return predicate.Role(sql.FieldLT(FieldRemark, v)) +} + +// RemarkLTE applies the LTE predicate on the "remark" field. +func RemarkLTE(v string) predicate.Role { + return predicate.Role(sql.FieldLTE(FieldRemark, v)) +} + +// RemarkContains applies the Contains predicate on the "remark" field. +func RemarkContains(v string) predicate.Role { + return predicate.Role(sql.FieldContains(FieldRemark, v)) +} + +// RemarkHasPrefix applies the HasPrefix predicate on the "remark" field. +func RemarkHasPrefix(v string) predicate.Role { + return predicate.Role(sql.FieldHasPrefix(FieldRemark, v)) +} + +// RemarkHasSuffix applies the HasSuffix predicate on the "remark" field. +func RemarkHasSuffix(v string) predicate.Role { + return predicate.Role(sql.FieldHasSuffix(FieldRemark, v)) +} + +// RemarkIsNil applies the IsNil predicate on the "remark" field. +func RemarkIsNil() predicate.Role { + return predicate.Role(sql.FieldIsNull(FieldRemark)) +} + +// RemarkNotNil applies the NotNil predicate on the "remark" field. +func RemarkNotNil() predicate.Role { + return predicate.Role(sql.FieldNotNull(FieldRemark)) +} + +// RemarkEqualFold applies the EqualFold predicate on the "remark" field. +func RemarkEqualFold(v string) predicate.Role { + return predicate.Role(sql.FieldEqualFold(FieldRemark, v)) +} + +// RemarkContainsFold applies the ContainsFold predicate on the "remark" field. +func RemarkContainsFold(v string) predicate.Role { + return predicate.Role(sql.FieldContainsFold(FieldRemark, v)) +} + +// PermissionCodesIsNil applies the IsNil predicate on the "permission_codes" field. +func PermissionCodesIsNil() predicate.Role { + return predicate.Role(sql.FieldIsNull(FieldPermissionCodes)) +} + +// PermissionCodesNotNil applies the NotNil predicate on the "permission_codes" field. +func PermissionCodesNotNil() predicate.Role { + return predicate.Role(sql.FieldNotNull(FieldPermissionCodes)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v int64) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v int64) predicate.Role { + return predicate.Role(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...int64) predicate.Role { + return predicate.Role(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...int64) predicate.Role { + return predicate.Role(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v int64) predicate.Role { + return predicate.Role(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v int64) predicate.Role { + return predicate.Role(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v int64) predicate.Role { + return predicate.Role(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v int64) predicate.Role { + return predicate.Role(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v int64) predicate.Role { + return predicate.Role(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v int64) predicate.Role { + return predicate.Role(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...int64) predicate.Role { + return predicate.Role(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...int64) predicate.Role { + return predicate.Role(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v int64) predicate.Role { + return predicate.Role(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v int64) predicate.Role { + return predicate.Role(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v int64) predicate.Role { + return predicate.Role(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v int64) predicate.Role { + return predicate.Role(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Role) predicate.Role { + return predicate.Role(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Role) predicate.Role { + return predicate.Role(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Role) predicate.Role { + return predicate.Role(sql.NotPredicates(p)) +} diff --git a/bj_power_wms/ent/role_create.go b/bj_power_wms/ent/role_create.go new file mode 100644 index 0000000..2461563 --- /dev/null +++ b/bj_power_wms/ent/role_create.go @@ -0,0 +1,850 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/role" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// RoleCreate is the builder for creating a Role entity. +type RoleCreate struct { + config + mutation *RoleMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetName sets the "name" field. +func (_c *RoleCreate) SetName(v string) *RoleCreate { + _c.mutation.SetName(v) + return _c +} + +// SetCode sets the "code" field. +func (_c *RoleCreate) SetCode(v string) *RoleCreate { + _c.mutation.SetCode(v) + return _c +} + +// SetRemark sets the "remark" field. +func (_c *RoleCreate) SetRemark(v string) *RoleCreate { + _c.mutation.SetRemark(v) + return _c +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_c *RoleCreate) SetNillableRemark(v *string) *RoleCreate { + if v != nil { + _c.SetRemark(*v) + } + return _c +} + +// SetPermissionCodes sets the "permission_codes" field. +func (_c *RoleCreate) SetPermissionCodes(v []string) *RoleCreate { + _c.mutation.SetPermissionCodes(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *RoleCreate) SetCreatedAt(v int64) *RoleCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *RoleCreate) SetNillableCreatedAt(v *int64) *RoleCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *RoleCreate) SetUpdatedAt(v int64) *RoleCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_c *RoleCreate) SetNillableUpdatedAt(v *int64) *RoleCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// Mutation returns the RoleMutation object of the builder. +func (_c *RoleCreate) Mutation() *RoleMutation { + return _c.mutation +} + +// Save creates the Role in the database. +func (_c *RoleCreate) Save(ctx context.Context) (*Role, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *RoleCreate) SaveX(ctx context.Context) *Role { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *RoleCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *RoleCreate) 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 *RoleCreate) defaults() { + if _, ok := _c.mutation.Remark(); !ok { + v := role.DefaultRemark + _c.mutation.SetRemark(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := role.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := role.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *RoleCreate) check() error { + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Role.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := role.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Role.name": %w`, err)} + } + } + if _, ok := _c.mutation.Code(); !ok { + return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "Role.code"`)} + } + if v, ok := _c.mutation.Code(); ok { + if err := role.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Role.code": %w`, err)} + } + } + if v, ok := _c.mutation.Remark(); ok { + if err := role.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Role.remark": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Role.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Role.updated_at"`)} + } + return nil +} + +func (_c *RoleCreate) sqlSave(ctx context.Context) (*Role, 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 + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *RoleCreate) createSpec() (*Role, *sqlgraph.CreateSpec) { + var ( + _node = &Role{config: _c.config} + _spec = sqlgraph.NewCreateSpec(role.Table, sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt)) + ) + _spec.OnConflict = _c.conflict + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(role.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Code(); ok { + _spec.SetField(role.FieldCode, field.TypeString, value) + _node.Code = value + } + if value, ok := _c.mutation.Remark(); ok { + _spec.SetField(role.FieldRemark, field.TypeString, value) + _node.Remark = value + } + if value, ok := _c.mutation.PermissionCodes(); ok { + _spec.SetField(role.FieldPermissionCodes, field.TypeJSON, value) + _node.PermissionCodes = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(role.FieldCreatedAt, field.TypeInt64, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(role.FieldUpdatedAt, field.TypeInt64, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Role.Create(). +// SetName(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.RoleUpsert) { +// SetName(v+v). +// }). +// Exec(ctx) +func (_c *RoleCreate) OnConflict(opts ...sql.ConflictOption) *RoleUpsertOne { + _c.conflict = opts + return &RoleUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Role.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *RoleCreate) OnConflictColumns(columns ...string) *RoleUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &RoleUpsertOne{ + create: _c, + } +} + +type ( + // RoleUpsertOne is the builder for "upsert"-ing + // one Role node. + RoleUpsertOne struct { + create *RoleCreate + } + + // RoleUpsert is the "OnConflict" setter. + RoleUpsert struct { + *sql.UpdateSet + } +) + +// SetName sets the "name" field. +func (u *RoleUpsert) SetName(v string) *RoleUpsert { + u.Set(role.FieldName, v) + return u +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *RoleUpsert) UpdateName() *RoleUpsert { + u.SetExcluded(role.FieldName) + return u +} + +// SetCode sets the "code" field. +func (u *RoleUpsert) SetCode(v string) *RoleUpsert { + u.Set(role.FieldCode, v) + return u +} + +// UpdateCode sets the "code" field to the value that was provided on create. +func (u *RoleUpsert) UpdateCode() *RoleUpsert { + u.SetExcluded(role.FieldCode) + return u +} + +// SetRemark sets the "remark" field. +func (u *RoleUpsert) SetRemark(v string) *RoleUpsert { + u.Set(role.FieldRemark, v) + return u +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *RoleUpsert) UpdateRemark() *RoleUpsert { + u.SetExcluded(role.FieldRemark) + return u +} + +// ClearRemark clears the value of the "remark" field. +func (u *RoleUpsert) ClearRemark() *RoleUpsert { + u.SetNull(role.FieldRemark) + return u +} + +// SetPermissionCodes sets the "permission_codes" field. +func (u *RoleUpsert) SetPermissionCodes(v []string) *RoleUpsert { + u.Set(role.FieldPermissionCodes, v) + return u +} + +// UpdatePermissionCodes sets the "permission_codes" field to the value that was provided on create. +func (u *RoleUpsert) UpdatePermissionCodes() *RoleUpsert { + u.SetExcluded(role.FieldPermissionCodes) + return u +} + +// ClearPermissionCodes clears the value of the "permission_codes" field. +func (u *RoleUpsert) ClearPermissionCodes() *RoleUpsert { + u.SetNull(role.FieldPermissionCodes) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *RoleUpsert) SetCreatedAt(v int64) *RoleUpsert { + u.Set(role.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *RoleUpsert) UpdateCreatedAt() *RoleUpsert { + u.SetExcluded(role.FieldCreatedAt) + return u +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *RoleUpsert) AddCreatedAt(v int64) *RoleUpsert { + u.Add(role.FieldCreatedAt, v) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *RoleUpsert) SetUpdatedAt(v int64) *RoleUpsert { + u.Set(role.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *RoleUpsert) UpdateUpdatedAt() *RoleUpsert { + u.SetExcluded(role.FieldUpdatedAt) + return u +} + +// AddUpdatedAt adds v to the "updated_at" field. +func (u *RoleUpsert) AddUpdatedAt(v int64) *RoleUpsert { + u.Add(role.FieldUpdatedAt, v) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create. +// Using this option is equivalent to using: +// +// client.Role.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *RoleUpsertOne) UpdateNewValues() *RoleUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Role.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *RoleUpsertOne) Ignore() *RoleUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *RoleUpsertOne) DoNothing() *RoleUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the RoleCreate.OnConflict +// documentation for more info. +func (u *RoleUpsertOne) Update(set func(*RoleUpsert)) *RoleUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&RoleUpsert{UpdateSet: update}) + })) + return u +} + +// SetName sets the "name" field. +func (u *RoleUpsertOne) SetName(v string) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *RoleUpsertOne) UpdateName() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.UpdateName() + }) +} + +// SetCode sets the "code" field. +func (u *RoleUpsertOne) SetCode(v string) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.SetCode(v) + }) +} + +// UpdateCode sets the "code" field to the value that was provided on create. +func (u *RoleUpsertOne) UpdateCode() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.UpdateCode() + }) +} + +// SetRemark sets the "remark" field. +func (u *RoleUpsertOne) SetRemark(v string) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.SetRemark(v) + }) +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *RoleUpsertOne) UpdateRemark() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.UpdateRemark() + }) +} + +// ClearRemark clears the value of the "remark" field. +func (u *RoleUpsertOne) ClearRemark() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.ClearRemark() + }) +} + +// SetPermissionCodes sets the "permission_codes" field. +func (u *RoleUpsertOne) SetPermissionCodes(v []string) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.SetPermissionCodes(v) + }) +} + +// UpdatePermissionCodes sets the "permission_codes" field to the value that was provided on create. +func (u *RoleUpsertOne) UpdatePermissionCodes() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.UpdatePermissionCodes() + }) +} + +// ClearPermissionCodes clears the value of the "permission_codes" field. +func (u *RoleUpsertOne) ClearPermissionCodes() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.ClearPermissionCodes() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *RoleUpsertOne) SetCreatedAt(v int64) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *RoleUpsertOne) AddCreatedAt(v int64) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *RoleUpsertOne) UpdateCreatedAt() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *RoleUpsertOne) SetUpdatedAt(v int64) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.SetUpdatedAt(v) + }) +} + +// AddUpdatedAt adds v to the "updated_at" field. +func (u *RoleUpsertOne) AddUpdatedAt(v int64) *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.AddUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *RoleUpsertOne) UpdateUpdatedAt() *RoleUpsertOne { + return u.Update(func(s *RoleUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *RoleUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for RoleCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *RoleUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *RoleUpsertOne) ID(ctx context.Context) (id int, err error) { + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *RoleUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// RoleCreateBulk is the builder for creating many Role entities in bulk. +type RoleCreateBulk struct { + config + err error + builders []*RoleCreate + conflict []sql.ConflictOption +} + +// Save creates the Role entities in the database. +func (_c *RoleCreateBulk) Save(ctx context.Context) ([]*Role, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Role, 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.(*RoleMutation) + 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} + spec.OnConflict = _c.conflict + // 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 { + 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 *RoleCreateBulk) SaveX(ctx context.Context) []*Role { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *RoleCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *RoleCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.Role.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.RoleUpsert) { +// SetName(v+v). +// }). +// Exec(ctx) +func (_c *RoleCreateBulk) OnConflict(opts ...sql.ConflictOption) *RoleUpsertBulk { + _c.conflict = opts + return &RoleUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.Role.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *RoleCreateBulk) OnConflictColumns(columns ...string) *RoleUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &RoleUpsertBulk{ + create: _c, + } +} + +// RoleUpsertBulk is the builder for "upsert"-ing +// a bulk of Role nodes. +type RoleUpsertBulk struct { + create *RoleCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.Role.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *RoleUpsertBulk) UpdateNewValues() *RoleUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.Role.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *RoleUpsertBulk) Ignore() *RoleUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *RoleUpsertBulk) DoNothing() *RoleUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the RoleCreateBulk.OnConflict +// documentation for more info. +func (u *RoleUpsertBulk) Update(set func(*RoleUpsert)) *RoleUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&RoleUpsert{UpdateSet: update}) + })) + return u +} + +// SetName sets the "name" field. +func (u *RoleUpsertBulk) SetName(v string) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *RoleUpsertBulk) UpdateName() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.UpdateName() + }) +} + +// SetCode sets the "code" field. +func (u *RoleUpsertBulk) SetCode(v string) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.SetCode(v) + }) +} + +// UpdateCode sets the "code" field to the value that was provided on create. +func (u *RoleUpsertBulk) UpdateCode() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.UpdateCode() + }) +} + +// SetRemark sets the "remark" field. +func (u *RoleUpsertBulk) SetRemark(v string) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.SetRemark(v) + }) +} + +// UpdateRemark sets the "remark" field to the value that was provided on create. +func (u *RoleUpsertBulk) UpdateRemark() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.UpdateRemark() + }) +} + +// ClearRemark clears the value of the "remark" field. +func (u *RoleUpsertBulk) ClearRemark() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.ClearRemark() + }) +} + +// SetPermissionCodes sets the "permission_codes" field. +func (u *RoleUpsertBulk) SetPermissionCodes(v []string) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.SetPermissionCodes(v) + }) +} + +// UpdatePermissionCodes sets the "permission_codes" field to the value that was provided on create. +func (u *RoleUpsertBulk) UpdatePermissionCodes() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.UpdatePermissionCodes() + }) +} + +// ClearPermissionCodes clears the value of the "permission_codes" field. +func (u *RoleUpsertBulk) ClearPermissionCodes() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.ClearPermissionCodes() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *RoleUpsertBulk) SetCreatedAt(v int64) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.SetCreatedAt(v) + }) +} + +// AddCreatedAt adds v to the "created_at" field. +func (u *RoleUpsertBulk) AddCreatedAt(v int64) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.AddCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *RoleUpsertBulk) UpdateCreatedAt() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *RoleUpsertBulk) SetUpdatedAt(v int64) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.SetUpdatedAt(v) + }) +} + +// AddUpdatedAt adds v to the "updated_at" field. +func (u *RoleUpsertBulk) AddUpdatedAt(v int64) *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.AddUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *RoleUpsertBulk) UpdateUpdatedAt() *RoleUpsertBulk { + return u.Update(func(s *RoleUpsert) { + s.UpdateUpdatedAt() + }) +} + +// Exec executes the query. +func (u *RoleUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the RoleCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for RoleCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *RoleUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_wms/ent/role_delete.go b/bj_power_wms/ent/role_delete.go new file mode 100644 index 0000000..3634f9c --- /dev/null +++ b/bj_power_wms/ent/role_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/predicate" + "bj_power_wms/ent/role" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// RoleDelete is the builder for deleting a Role entity. +type RoleDelete struct { + config + hooks []Hook + mutation *RoleMutation +} + +// Where appends a list predicates to the RoleDelete builder. +func (_d *RoleDelete) Where(ps ...predicate.Role) *RoleDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *RoleDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *RoleDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *RoleDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(role.Table, sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// RoleDeleteOne is the builder for deleting a single Role entity. +type RoleDeleteOne struct { + _d *RoleDelete +} + +// Where appends a list predicates to the RoleDelete builder. +func (_d *RoleDeleteOne) Where(ps ...predicate.Role) *RoleDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *RoleDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{role.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *RoleDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_wms/ent/role_query.go b/bj_power_wms/ent/role_query.go new file mode 100644 index 0000000..0e00fed --- /dev/null +++ b/bj_power_wms/ent/role_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/predicate" + "bj_power_wms/ent/role" + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// RoleQuery is the builder for querying Role entities. +type RoleQuery struct { + config + ctx *QueryContext + order []role.OrderOption + inters []Interceptor + predicates []predicate.Role + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the RoleQuery builder. +func (_q *RoleQuery) Where(ps ...predicate.Role) *RoleQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *RoleQuery) Limit(limit int) *RoleQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *RoleQuery) Offset(offset int) *RoleQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *RoleQuery) Unique(unique bool) *RoleQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *RoleQuery) Order(o ...role.OrderOption) *RoleQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first Role entity from the query. +// Returns a *NotFoundError when no Role was found. +func (_q *RoleQuery) First(ctx context.Context) (*Role, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{role.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *RoleQuery) FirstX(ctx context.Context) *Role { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Role ID from the query. +// Returns a *NotFoundError when no Role ID was found. +func (_q *RoleQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{role.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *RoleQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Role entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Role entity is found. +// Returns a *NotFoundError when no Role entities are found. +func (_q *RoleQuery) Only(ctx context.Context) (*Role, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{role.Label} + default: + return nil, &NotSingularError{role.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *RoleQuery) OnlyX(ctx context.Context) *Role { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Role ID in the query. +// Returns a *NotSingularError when more than one Role ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *RoleQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{role.Label} + default: + err = &NotSingularError{role.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *RoleQuery) OnlyIDX(ctx context.Context) int { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Roles. +func (_q *RoleQuery) All(ctx context.Context) ([]*Role, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Role, *RoleQuery]() + return withInterceptors[[]*Role](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *RoleQuery) AllX(ctx context.Context) []*Role { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Role IDs. +func (_q *RoleQuery) IDs(ctx context.Context) (ids []int, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(role.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *RoleQuery) IDsX(ctx context.Context) []int { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *RoleQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*RoleQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *RoleQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *RoleQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *RoleQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the RoleQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *RoleQuery) Clone() *RoleQuery { + if _q == nil { + return nil + } + return &RoleQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]role.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Role{}, _q.predicates...), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Name string `json:"name,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Role.Query(). +// GroupBy(role.FieldName). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *RoleQuery) GroupBy(field string, fields ...string) *RoleGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &RoleGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = role.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Name string `json:"name,omitempty"` +// } +// +// client.Role.Query(). +// Select(role.FieldName). +// Scan(ctx, &v) +func (_q *RoleQuery) Select(fields ...string) *RoleSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &RoleSelect{RoleQuery: _q} + sbuild.label = role.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a RoleSelect configured with the given aggregations. +func (_q *RoleQuery) Aggregate(fns ...AggregateFunc) *RoleSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *RoleQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !role.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *RoleQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Role, error) { + var ( + nodes = []*Role{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Role).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Role{config: _q.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (_q *RoleQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *RoleQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(role.Table, role.Columns, sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, role.FieldID) + for i := range fields { + if fields[i] != role.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *RoleQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(role.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = role.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// RoleGroupBy is the group-by builder for Role entities. +type RoleGroupBy struct { + selector + build *RoleQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *RoleGroupBy) Aggregate(fns ...AggregateFunc) *RoleGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *RoleGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*RoleQuery, *RoleGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *RoleGroupBy) sqlScan(ctx context.Context, root *RoleQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// RoleSelect is the builder for selecting fields of Role entities. +type RoleSelect struct { + *RoleQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *RoleSelect) Aggregate(fns ...AggregateFunc) *RoleSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *RoleSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*RoleQuery, *RoleSelect](ctx, _s.RoleQuery, _s, _s.inters, v) +} + +func (_s *RoleSelect) sqlScan(ctx context.Context, root *RoleQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/bj_power_wms/ent/role_update.go b/bj_power_wms/ent/role_update.go new file mode 100644 index 0000000..3a3120e --- /dev/null +++ b/bj_power_wms/ent/role_update.go @@ -0,0 +1,508 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_wms/ent/predicate" + "bj_power_wms/ent/role" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" + "entgo.io/ent/schema/field" +) + +// RoleUpdate is the builder for updating Role entities. +type RoleUpdate struct { + config + hooks []Hook + mutation *RoleMutation +} + +// Where appends a list predicates to the RoleUpdate builder. +func (_u *RoleUpdate) Where(ps ...predicate.Role) *RoleUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetName sets the "name" field. +func (_u *RoleUpdate) SetName(v string) *RoleUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *RoleUpdate) SetNillableName(v *string) *RoleUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetCode sets the "code" field. +func (_u *RoleUpdate) SetCode(v string) *RoleUpdate { + _u.mutation.SetCode(v) + return _u +} + +// SetNillableCode sets the "code" field if the given value is not nil. +func (_u *RoleUpdate) SetNillableCode(v *string) *RoleUpdate { + if v != nil { + _u.SetCode(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *RoleUpdate) SetRemark(v string) *RoleUpdate { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *RoleUpdate) SetNillableRemark(v *string) *RoleUpdate { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// ClearRemark clears the value of the "remark" field. +func (_u *RoleUpdate) ClearRemark() *RoleUpdate { + _u.mutation.ClearRemark() + return _u +} + +// SetPermissionCodes sets the "permission_codes" field. +func (_u *RoleUpdate) SetPermissionCodes(v []string) *RoleUpdate { + _u.mutation.SetPermissionCodes(v) + return _u +} + +// AppendPermissionCodes appends value to the "permission_codes" field. +func (_u *RoleUpdate) AppendPermissionCodes(v []string) *RoleUpdate { + _u.mutation.AppendPermissionCodes(v) + return _u +} + +// ClearPermissionCodes clears the value of the "permission_codes" field. +func (_u *RoleUpdate) ClearPermissionCodes() *RoleUpdate { + _u.mutation.ClearPermissionCodes() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *RoleUpdate) SetCreatedAt(v int64) *RoleUpdate { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *RoleUpdate) SetNillableCreatedAt(v *int64) *RoleUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *RoleUpdate) AddCreatedAt(v int64) *RoleUpdate { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *RoleUpdate) SetUpdatedAt(v int64) *RoleUpdate { + _u.mutation.ResetUpdatedAt() + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *RoleUpdate) SetNillableUpdatedAt(v *int64) *RoleUpdate { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// AddUpdatedAt adds value to the "updated_at" field. +func (_u *RoleUpdate) AddUpdatedAt(v int64) *RoleUpdate { + _u.mutation.AddUpdatedAt(v) + return _u +} + +// Mutation returns the RoleMutation object of the builder. +func (_u *RoleUpdate) Mutation() *RoleMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *RoleUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *RoleUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *RoleUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *RoleUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *RoleUpdate) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := role.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Role.name": %w`, err)} + } + } + if v, ok := _u.mutation.Code(); ok { + if err := role.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Role.code": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := role.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Role.remark": %w`, err)} + } + } + return nil +} + +func (_u *RoleUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(role.Table, role.Columns, sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(role.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Code(); ok { + _spec.SetField(role.FieldCode, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(role.FieldRemark, field.TypeString, value) + } + if _u.mutation.RemarkCleared() { + _spec.ClearField(role.FieldRemark, field.TypeString) + } + if value, ok := _u.mutation.PermissionCodes(); ok { + _spec.SetField(role.FieldPermissionCodes, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedPermissionCodes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, role.FieldPermissionCodes, value) + }) + } + if _u.mutation.PermissionCodesCleared() { + _spec.ClearField(role.FieldPermissionCodes, field.TypeJSON) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(role.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(role.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(role.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedUpdatedAt(); ok { + _spec.AddField(role.FieldUpdatedAt, field.TypeInt64, value) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{role.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// RoleUpdateOne is the builder for updating a single Role entity. +type RoleUpdateOne struct { + config + fields []string + hooks []Hook + mutation *RoleMutation +} + +// SetName sets the "name" field. +func (_u *RoleUpdateOne) SetName(v string) *RoleUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *RoleUpdateOne) SetNillableName(v *string) *RoleUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetCode sets the "code" field. +func (_u *RoleUpdateOne) SetCode(v string) *RoleUpdateOne { + _u.mutation.SetCode(v) + return _u +} + +// SetNillableCode sets the "code" field if the given value is not nil. +func (_u *RoleUpdateOne) SetNillableCode(v *string) *RoleUpdateOne { + if v != nil { + _u.SetCode(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *RoleUpdateOne) SetRemark(v string) *RoleUpdateOne { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *RoleUpdateOne) SetNillableRemark(v *string) *RoleUpdateOne { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// ClearRemark clears the value of the "remark" field. +func (_u *RoleUpdateOne) ClearRemark() *RoleUpdateOne { + _u.mutation.ClearRemark() + return _u +} + +// SetPermissionCodes sets the "permission_codes" field. +func (_u *RoleUpdateOne) SetPermissionCodes(v []string) *RoleUpdateOne { + _u.mutation.SetPermissionCodes(v) + return _u +} + +// AppendPermissionCodes appends value to the "permission_codes" field. +func (_u *RoleUpdateOne) AppendPermissionCodes(v []string) *RoleUpdateOne { + _u.mutation.AppendPermissionCodes(v) + return _u +} + +// ClearPermissionCodes clears the value of the "permission_codes" field. +func (_u *RoleUpdateOne) ClearPermissionCodes() *RoleUpdateOne { + _u.mutation.ClearPermissionCodes() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *RoleUpdateOne) SetCreatedAt(v int64) *RoleUpdateOne { + _u.mutation.ResetCreatedAt() + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *RoleUpdateOne) SetNillableCreatedAt(v *int64) *RoleUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// AddCreatedAt adds value to the "created_at" field. +func (_u *RoleUpdateOne) AddCreatedAt(v int64) *RoleUpdateOne { + _u.mutation.AddCreatedAt(v) + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *RoleUpdateOne) SetUpdatedAt(v int64) *RoleUpdateOne { + _u.mutation.ResetUpdatedAt() + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *RoleUpdateOne) SetNillableUpdatedAt(v *int64) *RoleUpdateOne { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// AddUpdatedAt adds value to the "updated_at" field. +func (_u *RoleUpdateOne) AddUpdatedAt(v int64) *RoleUpdateOne { + _u.mutation.AddUpdatedAt(v) + return _u +} + +// Mutation returns the RoleMutation object of the builder. +func (_u *RoleUpdateOne) Mutation() *RoleMutation { + return _u.mutation +} + +// Where appends a list predicates to the RoleUpdate builder. +func (_u *RoleUpdateOne) Where(ps ...predicate.Role) *RoleUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *RoleUpdateOne) Select(field string, fields ...string) *RoleUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Role entity. +func (_u *RoleUpdateOne) Save(ctx context.Context) (*Role, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *RoleUpdateOne) SaveX(ctx context.Context) *Role { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *RoleUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *RoleUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *RoleUpdateOne) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := role.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Role.name": %w`, err)} + } + } + if v, ok := _u.mutation.Code(); ok { + if err := role.CodeValidator(v); err != nil { + return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Role.code": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := role.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Role.remark": %w`, err)} + } + } + return nil +} + +func (_u *RoleUpdateOne) sqlSave(ctx context.Context) (_node *Role, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(role.Table, role.Columns, sqlgraph.NewFieldSpec(role.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Role.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, role.FieldID) + for _, f := range fields { + if !role.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != role.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(role.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Code(); ok { + _spec.SetField(role.FieldCode, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(role.FieldRemark, field.TypeString, value) + } + if _u.mutation.RemarkCleared() { + _spec.ClearField(role.FieldRemark, field.TypeString) + } + if value, ok := _u.mutation.PermissionCodes(); ok { + _spec.SetField(role.FieldPermissionCodes, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedPermissionCodes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, role.FieldPermissionCodes, value) + }) + } + if _u.mutation.PermissionCodesCleared() { + _spec.ClearField(role.FieldPermissionCodes, field.TypeJSON) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(role.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedCreatedAt(); ok { + _spec.AddField(role.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(role.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedUpdatedAt(); ok { + _spec.AddField(role.FieldUpdatedAt, field.TypeInt64, value) + } + _node = &Role{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{role.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/bj_power_wms/ent/runtime.go b/bj_power_wms/ent/runtime.go index 30b3f27..dc639ca 100644 --- a/bj_power_wms/ent/runtime.go +++ b/bj_power_wms/ent/runtime.go @@ -12,7 +12,8 @@ import ( "bj_power_wms/ent/ordermaterialledger" "bj_power_wms/ent/outbounddetail" "bj_power_wms/ent/outboundorder" - "bj_power_wms/ent/packagebox" + "bj_power_wms/ent/permission" + "bj_power_wms/ent/role" "bj_power_wms/ent/semifinished" "bj_power_wms/ent/stocktakeitem" "bj_power_wms/ent/stocktakeorder" @@ -63,12 +64,20 @@ func init() { inspectionrecordDescStatus := inspectionrecordFields[4].Descriptor() // inspectionrecord.DefaultStatus holds the default value on creation for the status field. inspectionrecord.DefaultStatus = inspectionrecordDescStatus.Default.(string) + // inspectionrecordDescInspectQty is the schema descriptor for inspect_qty field. + inspectionrecordDescInspectQty := inspectionrecordFields[6].Descriptor() + // inspectionrecord.DefaultInspectQty holds the default value on creation for the inspect_qty field. + inspectionrecord.DefaultInspectQty = inspectionrecordDescInspectQty.Default.(int) + // inspectionrecordDescPassQty is the schema descriptor for pass_qty field. + inspectionrecordDescPassQty := inspectionrecordFields[7].Descriptor() + // inspectionrecord.DefaultPassQty holds the default value on creation for the pass_qty field. + inspectionrecord.DefaultPassQty = inspectionrecordDescPassQty.Default.(int) // inspectionrecordDescCreatedAt is the schema descriptor for created_at field. - inspectionrecordDescCreatedAt := inspectionrecordFields[8].Descriptor() + inspectionrecordDescCreatedAt := inspectionrecordFields[12].Descriptor() // inspectionrecord.DefaultCreatedAt holds the default value on creation for the created_at field. inspectionrecord.DefaultCreatedAt = inspectionrecordDescCreatedAt.Default.(func() int64) // inspectionrecordDescUpdatedAt is the schema descriptor for updated_at field. - inspectionrecordDescUpdatedAt := inspectionrecordFields[9].Descriptor() + inspectionrecordDescUpdatedAt := inspectionrecordFields[13].Descriptor() // inspectionrecord.DefaultUpdatedAt holds the default value on creation for the updated_at field. inspectionrecord.DefaultUpdatedAt = inspectionrecordDescUpdatedAt.Default.(func() int64) inventoryFields := schema.Inventory{}.Fields() @@ -184,23 +193,79 @@ func init() { // outboundorder.DefaultQuantity holds the default value on creation for the quantity field. outboundorder.DefaultQuantity = outboundorderDescQuantity.Default.(int) // outboundorderDescCreatedAt is the schema descriptor for created_at field. - outboundorderDescCreatedAt := outboundorderFields[13].Descriptor() + outboundorderDescCreatedAt := outboundorderFields[16].Descriptor() // outboundorder.DefaultCreatedAt holds the default value on creation for the created_at field. outboundorder.DefaultCreatedAt = outboundorderDescCreatedAt.Default.(func() int64) - packageboxFields := schema.PackageBox{}.Fields() - _ = packageboxFields - // packageboxDescQuantity is the schema descriptor for quantity field. - packageboxDescQuantity := packageboxFields[3].Descriptor() - // packagebox.DefaultQuantity holds the default value on creation for the quantity field. - packagebox.DefaultQuantity = packageboxDescQuantity.Default.(int) - // packageboxDescCreatedAt is the schema descriptor for created_at field. - packageboxDescCreatedAt := packageboxFields[7].Descriptor() - // packagebox.DefaultCreatedAt holds the default value on creation for the created_at field. - packagebox.DefaultCreatedAt = packageboxDescCreatedAt.Default.(func() int64) - // packageboxDescUpdatedAt is the schema descriptor for updated_at field. - packageboxDescUpdatedAt := packageboxFields[8].Descriptor() - // packagebox.DefaultUpdatedAt holds the default value on creation for the updated_at field. - packagebox.DefaultUpdatedAt = packageboxDescUpdatedAt.Default.(func() int64) + permissionFields := schema.Permission{}.Fields() + _ = permissionFields + // permissionDescCode is the schema descriptor for code field. + permissionDescCode := permissionFields[0].Descriptor() + // permission.CodeValidator is a validator for the "code" field. It is called by the builders before save. + permission.CodeValidator = permissionDescCode.Validators[0].(func(string) error) + // permissionDescName is the schema descriptor for name field. + permissionDescName := permissionFields[1].Descriptor() + // permission.NameValidator is a validator for the "name" field. It is called by the builders before save. + permission.NameValidator = permissionDescName.Validators[0].(func(string) error) + // permissionDescType is the schema descriptor for type field. + permissionDescType := permissionFields[2].Descriptor() + // permission.DefaultType holds the default value on creation for the type field. + permission.DefaultType = permissionDescType.Default.(string) + // permission.TypeValidator is a validator for the "type" field. It is called by the builders before save. + permission.TypeValidator = permissionDescType.Validators[0].(func(string) error) + // permissionDescPath is the schema descriptor for path field. + permissionDescPath := permissionFields[3].Descriptor() + // permission.DefaultPath holds the default value on creation for the path field. + permission.DefaultPath = permissionDescPath.Default.(string) + // permission.PathValidator is a validator for the "path" field. It is called by the builders before save. + permission.PathValidator = permissionDescPath.Validators[0].(func(string) error) + // permissionDescIcon is the schema descriptor for icon field. + permissionDescIcon := permissionFields[4].Descriptor() + // permission.DefaultIcon holds the default value on creation for the icon field. + permission.DefaultIcon = permissionDescIcon.Default.(string) + // permission.IconValidator is a validator for the "icon" field. It is called by the builders before save. + permission.IconValidator = permissionDescIcon.Validators[0].(func(string) error) + // permissionDescSort is the schema descriptor for sort field. + permissionDescSort := permissionFields[5].Descriptor() + // permission.DefaultSort holds the default value on creation for the sort field. + permission.DefaultSort = permissionDescSort.Default.(int) + // permissionDescRemark is the schema descriptor for remark field. + permissionDescRemark := permissionFields[6].Descriptor() + // permission.DefaultRemark holds the default value on creation for the remark field. + permission.DefaultRemark = permissionDescRemark.Default.(string) + // permission.RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + permission.RemarkValidator = permissionDescRemark.Validators[0].(func(string) error) + // permissionDescCreatedAt is the schema descriptor for created_at field. + permissionDescCreatedAt := permissionFields[7].Descriptor() + // permission.DefaultCreatedAt holds the default value on creation for the created_at field. + permission.DefaultCreatedAt = permissionDescCreatedAt.Default.(func() int64) + // permissionDescUpdatedAt is the schema descriptor for updated_at field. + permissionDescUpdatedAt := permissionFields[8].Descriptor() + // permission.DefaultUpdatedAt holds the default value on creation for the updated_at field. + permission.DefaultUpdatedAt = permissionDescUpdatedAt.Default.(func() int64) + roleFields := schema.Role{}.Fields() + _ = roleFields + // roleDescName is the schema descriptor for name field. + roleDescName := roleFields[0].Descriptor() + // role.NameValidator is a validator for the "name" field. It is called by the builders before save. + role.NameValidator = roleDescName.Validators[0].(func(string) error) + // roleDescCode is the schema descriptor for code field. + roleDescCode := roleFields[1].Descriptor() + // role.CodeValidator is a validator for the "code" field. It is called by the builders before save. + role.CodeValidator = roleDescCode.Validators[0].(func(string) error) + // roleDescRemark is the schema descriptor for remark field. + roleDescRemark := roleFields[2].Descriptor() + // role.DefaultRemark holds the default value on creation for the remark field. + role.DefaultRemark = roleDescRemark.Default.(string) + // role.RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + role.RemarkValidator = roleDescRemark.Validators[0].(func(string) error) + // roleDescCreatedAt is the schema descriptor for created_at field. + roleDescCreatedAt := roleFields[4].Descriptor() + // role.DefaultCreatedAt holds the default value on creation for the created_at field. + role.DefaultCreatedAt = roleDescCreatedAt.Default.(func() int64) + // roleDescUpdatedAt is the schema descriptor for updated_at field. + roleDescUpdatedAt := roleFields[5].Descriptor() + // role.DefaultUpdatedAt holds the default value on creation for the updated_at field. + role.DefaultUpdatedAt = roleDescUpdatedAt.Default.(func() int64) semifinishedFields := schema.SemiFinished{}.Fields() _ = semifinishedFields // semifinishedDescQuantity is the schema descriptor for quantity field. @@ -262,15 +327,15 @@ func init() { // user.DefaultRole holds the default value on creation for the role field. user.DefaultRole = userDescRole.Default.(string) // userDescIsActive is the schema descriptor for is_active field. - userDescIsActive := userFields[6].Descriptor() + userDescIsActive := userFields[7].Descriptor() // user.DefaultIsActive holds the default value on creation for the is_active field. user.DefaultIsActive = userDescIsActive.Default.(bool) // userDescCreatedAt is the schema descriptor for created_at field. - userDescCreatedAt := userFields[8].Descriptor() + userDescCreatedAt := userFields[9].Descriptor() // user.DefaultCreatedAt holds the default value on creation for the created_at field. user.DefaultCreatedAt = userDescCreatedAt.Default.(func() int64) // userDescUpdatedAt is the schema descriptor for updated_at field. - userDescUpdatedAt := userFields[9].Descriptor() + userDescUpdatedAt := userFields[10].Descriptor() // user.DefaultUpdatedAt holds the default value on creation for the updated_at field. user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() int64) zoneFields := schema.Zone{}.Fields() diff --git a/bj_power_wms/ent/stocktakeitem.go b/bj_power_wms/ent/stocktakeitem.go index 8571d7b..180062b 100644 --- a/bj_power_wms/ent/stocktakeitem.go +++ b/bj_power_wms/ent/stocktakeitem.go @@ -22,7 +22,7 @@ type StocktakeItem struct { TargetType string `json:"targetType,omitempty"` // 批次号或SN码 TargetID string `json:"targetId,omitempty"` - // MaterialCode holds the value of the "material_code" field. + // 物料编码(冗余,便于盘点差异按物料归类) MaterialCode string `json:"materialCode,omitempty"` // 所在区域 ZoneCode string `json:"zoneCode,omitempty"` diff --git a/bj_power_wms/ent/tx.go b/bj_power_wms/ent/tx.go index 2413d6a..e9be559 100644 --- a/bj_power_wms/ent/tx.go +++ b/bj_power_wms/ent/tx.go @@ -30,8 +30,10 @@ type Tx struct { OutboundDetail *OutboundDetailClient // OutboundOrder is the client for interacting with the OutboundOrder builders. OutboundOrder *OutboundOrderClient - // PackageBox is the client for interacting with the PackageBox builders. - PackageBox *PackageBoxClient + // Permission is the client for interacting with the Permission builders. + Permission *PermissionClient + // Role is the client for interacting with the Role builders. + Role *RoleClient // SemiFinished is the client for interacting with the SemiFinished builders. SemiFinished *SemiFinishedClient // StocktakeItem is the client for interacting with the StocktakeItem builders. @@ -182,7 +184,8 @@ func (tx *Tx) init() { tx.OrderMaterialLedger = NewOrderMaterialLedgerClient(tx.config) tx.OutboundDetail = NewOutboundDetailClient(tx.config) tx.OutboundOrder = NewOutboundOrderClient(tx.config) - tx.PackageBox = NewPackageBoxClient(tx.config) + tx.Permission = NewPermissionClient(tx.config) + tx.Role = NewRoleClient(tx.config) tx.SemiFinished = NewSemiFinishedClient(tx.config) tx.StocktakeItem = NewStocktakeItemClient(tx.config) tx.StocktakeOrder = NewStocktakeOrderClient(tx.config) diff --git a/bj_power_wms/ent/user.go b/bj_power_wms/ent/user.go index 9efa1eb..7d62329 100644 --- a/bj_power_wms/ent/user.go +++ b/bj_power_wms/ent/user.go @@ -22,8 +22,10 @@ type User struct { Password string `json:"password,omitempty"` // 姓名 RealName string `json:"realName,omitempty"` - // 角色 admin/operator/inspector + // 角色 admin/operator/inspector(旧字段,权限数据化后由 role_id 决定,此字段仅作兼容/展示) Role string `json:"role,omitempty"` + // 角色ID,关联 roles 表;为空时回退按 role 字符串取权限 + RoleID int `json:"roleId,omitempty"` // 部门 Dept string `json:"dept,omitempty"` // 电话 @@ -46,7 +48,7 @@ func (*User) scanValues(columns []string) ([]any, error) { switch columns[i] { case user.FieldIsActive: values[i] = new(sql.NullBool) - case user.FieldID, user.FieldLastLoginAt, user.FieldCreatedAt, user.FieldUpdatedAt: + case user.FieldID, user.FieldRoleID, user.FieldLastLoginAt, user.FieldCreatedAt, user.FieldUpdatedAt: values[i] = new(sql.NullInt64) case user.FieldUsername, user.FieldPassword, user.FieldRealName, user.FieldRole, user.FieldDept, user.FieldPhone: values[i] = new(sql.NullString) @@ -95,6 +97,12 @@ func (_m *User) assignValues(columns []string, values []any) error { } else if value.Valid { _m.Role = value.String } + case user.FieldRoleID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field role_id", values[i]) + } else if value.Valid { + _m.RoleID = int(value.Int64) + } case user.FieldDept: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field dept", values[i]) @@ -179,6 +187,9 @@ func (_m *User) String() string { builder.WriteString("role=") builder.WriteString(_m.Role) builder.WriteString(", ") + builder.WriteString("role_id=") + builder.WriteString(fmt.Sprintf("%v", _m.RoleID)) + builder.WriteString(", ") builder.WriteString("dept=") builder.WriteString(_m.Dept) builder.WriteString(", ") diff --git a/bj_power_wms/ent/user/user.go b/bj_power_wms/ent/user/user.go index f8867e0..fc1ed7e 100644 --- a/bj_power_wms/ent/user/user.go +++ b/bj_power_wms/ent/user/user.go @@ -19,6 +19,8 @@ const ( FieldRealName = "real_name" // FieldRole holds the string denoting the role field in the database. FieldRole = "role" + // FieldRoleID holds the string denoting the role_id field in the database. + FieldRoleID = "role_id" // FieldDept holds the string denoting the dept field in the database. FieldDept = "dept" // FieldPhone holds the string denoting the phone field in the database. @@ -42,6 +44,7 @@ var Columns = []string{ FieldPassword, FieldRealName, FieldRole, + FieldRoleID, FieldDept, FieldPhone, FieldIsActive, @@ -99,6 +102,11 @@ func ByRole(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldRole, opts...).ToFunc() } +// ByRoleID orders the results by the role_id field. +func ByRoleID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRoleID, opts...).ToFunc() +} + // ByDept orders the results by the dept field. func ByDept(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldDept, opts...).ToFunc() diff --git a/bj_power_wms/ent/user/where.go b/bj_power_wms/ent/user/where.go index 4e1c418..937ac79 100644 --- a/bj_power_wms/ent/user/where.go +++ b/bj_power_wms/ent/user/where.go @@ -73,6 +73,11 @@ func Role(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldRole, v)) } +// RoleID applies equality check predicate on the "role_id" field. It's identical to RoleIDEQ. +func RoleID(v int) predicate.User { + return predicate.User(sql.FieldEQ(FieldRoleID, v)) +} + // Dept applies equality check predicate on the "dept" field. It's identical to DeptEQ. func Dept(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldDept, v)) @@ -373,6 +378,56 @@ func RoleContainsFold(v string) predicate.User { return predicate.User(sql.FieldContainsFold(FieldRole, v)) } +// RoleIDEQ applies the EQ predicate on the "role_id" field. +func RoleIDEQ(v int) predicate.User { + return predicate.User(sql.FieldEQ(FieldRoleID, v)) +} + +// RoleIDNEQ applies the NEQ predicate on the "role_id" field. +func RoleIDNEQ(v int) predicate.User { + return predicate.User(sql.FieldNEQ(FieldRoleID, v)) +} + +// RoleIDIn applies the In predicate on the "role_id" field. +func RoleIDIn(vs ...int) predicate.User { + return predicate.User(sql.FieldIn(FieldRoleID, vs...)) +} + +// RoleIDNotIn applies the NotIn predicate on the "role_id" field. +func RoleIDNotIn(vs ...int) predicate.User { + return predicate.User(sql.FieldNotIn(FieldRoleID, vs...)) +} + +// RoleIDGT applies the GT predicate on the "role_id" field. +func RoleIDGT(v int) predicate.User { + return predicate.User(sql.FieldGT(FieldRoleID, v)) +} + +// RoleIDGTE applies the GTE predicate on the "role_id" field. +func RoleIDGTE(v int) predicate.User { + return predicate.User(sql.FieldGTE(FieldRoleID, v)) +} + +// RoleIDLT applies the LT predicate on the "role_id" field. +func RoleIDLT(v int) predicate.User { + return predicate.User(sql.FieldLT(FieldRoleID, v)) +} + +// RoleIDLTE applies the LTE predicate on the "role_id" field. +func RoleIDLTE(v int) predicate.User { + return predicate.User(sql.FieldLTE(FieldRoleID, v)) +} + +// RoleIDIsNil applies the IsNil predicate on the "role_id" field. +func RoleIDIsNil() predicate.User { + return predicate.User(sql.FieldIsNull(FieldRoleID)) +} + +// RoleIDNotNil applies the NotNil predicate on the "role_id" field. +func RoleIDNotNil() predicate.User { + return predicate.User(sql.FieldNotNull(FieldRoleID)) +} + // DeptEQ applies the EQ predicate on the "dept" field. func DeptEQ(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldDept, v)) diff --git a/bj_power_wms/ent/user_create.go b/bj_power_wms/ent/user_create.go index d04cba1..0b82b17 100644 --- a/bj_power_wms/ent/user_create.go +++ b/bj_power_wms/ent/user_create.go @@ -61,6 +61,20 @@ func (_c *UserCreate) SetNillableRole(v *string) *UserCreate { return _c } +// SetRoleID sets the "role_id" field. +func (_c *UserCreate) SetRoleID(v int) *UserCreate { + _c.mutation.SetRoleID(v) + return _c +} + +// SetNillableRoleID sets the "role_id" field if the given value is not nil. +func (_c *UserCreate) SetNillableRoleID(v *int) *UserCreate { + if v != nil { + _c.SetRoleID(*v) + } + return _c +} + // SetDept sets the "dept" field. func (_c *UserCreate) SetDept(v string) *UserCreate { _c.mutation.SetDept(v) @@ -261,6 +275,10 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { _spec.SetField(user.FieldRole, field.TypeString, value) _node.Role = value } + if value, ok := _c.mutation.RoleID(); ok { + _spec.SetField(user.FieldRoleID, field.TypeInt, value) + _node.RoleID = value + } if value, ok := _c.mutation.Dept(); ok { _spec.SetField(user.FieldDept, field.TypeString, value) _node.Dept = value @@ -391,6 +409,30 @@ func (u *UserUpsert) UpdateRole() *UserUpsert { return u } +// SetRoleID sets the "role_id" field. +func (u *UserUpsert) SetRoleID(v int) *UserUpsert { + u.Set(user.FieldRoleID, v) + return u +} + +// UpdateRoleID sets the "role_id" field to the value that was provided on create. +func (u *UserUpsert) UpdateRoleID() *UserUpsert { + u.SetExcluded(user.FieldRoleID) + return u +} + +// AddRoleID adds v to the "role_id" field. +func (u *UserUpsert) AddRoleID(v int) *UserUpsert { + u.Add(user.FieldRoleID, v) + return u +} + +// ClearRoleID clears the value of the "role_id" field. +func (u *UserUpsert) ClearRoleID() *UserUpsert { + u.SetNull(user.FieldRoleID) + return u +} + // SetDept sets the "dept" field. func (u *UserUpsert) SetDept(v string) *UserUpsert { u.Set(user.FieldDept, v) @@ -602,6 +644,34 @@ func (u *UserUpsertOne) UpdateRole() *UserUpsertOne { }) } +// SetRoleID sets the "role_id" field. +func (u *UserUpsertOne) SetRoleID(v int) *UserUpsertOne { + return u.Update(func(s *UserUpsert) { + s.SetRoleID(v) + }) +} + +// AddRoleID adds v to the "role_id" field. +func (u *UserUpsertOne) AddRoleID(v int) *UserUpsertOne { + return u.Update(func(s *UserUpsert) { + s.AddRoleID(v) + }) +} + +// UpdateRoleID sets the "role_id" field to the value that was provided on create. +func (u *UserUpsertOne) UpdateRoleID() *UserUpsertOne { + return u.Update(func(s *UserUpsert) { + s.UpdateRoleID() + }) +} + +// ClearRoleID clears the value of the "role_id" field. +func (u *UserUpsertOne) ClearRoleID() *UserUpsertOne { + return u.Update(func(s *UserUpsert) { + s.ClearRoleID() + }) +} + // SetDept sets the "dept" field. func (u *UserUpsertOne) SetDept(v string) *UserUpsertOne { return u.Update(func(s *UserUpsert) { @@ -995,6 +1065,34 @@ func (u *UserUpsertBulk) UpdateRole() *UserUpsertBulk { }) } +// SetRoleID sets the "role_id" field. +func (u *UserUpsertBulk) SetRoleID(v int) *UserUpsertBulk { + return u.Update(func(s *UserUpsert) { + s.SetRoleID(v) + }) +} + +// AddRoleID adds v to the "role_id" field. +func (u *UserUpsertBulk) AddRoleID(v int) *UserUpsertBulk { + return u.Update(func(s *UserUpsert) { + s.AddRoleID(v) + }) +} + +// UpdateRoleID sets the "role_id" field to the value that was provided on create. +func (u *UserUpsertBulk) UpdateRoleID() *UserUpsertBulk { + return u.Update(func(s *UserUpsert) { + s.UpdateRoleID() + }) +} + +// ClearRoleID clears the value of the "role_id" field. +func (u *UserUpsertBulk) ClearRoleID() *UserUpsertBulk { + return u.Update(func(s *UserUpsert) { + s.ClearRoleID() + }) +} + // SetDept sets the "dept" field. func (u *UserUpsertBulk) SetDept(v string) *UserUpsertBulk { return u.Update(func(s *UserUpsert) { diff --git a/bj_power_wms/ent/user_update.go b/bj_power_wms/ent/user_update.go index ae94cae..0ed168c 100644 --- a/bj_power_wms/ent/user_update.go +++ b/bj_power_wms/ent/user_update.go @@ -89,6 +89,33 @@ func (_u *UserUpdate) SetNillableRole(v *string) *UserUpdate { return _u } +// SetRoleID sets the "role_id" field. +func (_u *UserUpdate) SetRoleID(v int) *UserUpdate { + _u.mutation.ResetRoleID() + _u.mutation.SetRoleID(v) + return _u +} + +// SetNillableRoleID sets the "role_id" field if the given value is not nil. +func (_u *UserUpdate) SetNillableRoleID(v *int) *UserUpdate { + if v != nil { + _u.SetRoleID(*v) + } + return _u +} + +// AddRoleID adds value to the "role_id" field. +func (_u *UserUpdate) AddRoleID(v int) *UserUpdate { + _u.mutation.AddRoleID(v) + return _u +} + +// ClearRoleID clears the value of the "role_id" field. +func (_u *UserUpdate) ClearRoleID() *UserUpdate { + _u.mutation.ClearRoleID() + return _u +} + // SetDept sets the "dept" field. func (_u *UserUpdate) SetDept(v string) *UserUpdate { _u.mutation.SetDept(v) @@ -268,6 +295,15 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) { if value, ok := _u.mutation.Role(); ok { _spec.SetField(user.FieldRole, field.TypeString, value) } + if value, ok := _u.mutation.RoleID(); ok { + _spec.SetField(user.FieldRoleID, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedRoleID(); ok { + _spec.AddField(user.FieldRoleID, field.TypeInt, value) + } + if _u.mutation.RoleIDCleared() { + _spec.ClearField(user.FieldRoleID, field.TypeInt) + } if value, ok := _u.mutation.Dept(); ok { _spec.SetField(user.FieldDept, field.TypeString, value) } @@ -386,6 +422,33 @@ func (_u *UserUpdateOne) SetNillableRole(v *string) *UserUpdateOne { return _u } +// SetRoleID sets the "role_id" field. +func (_u *UserUpdateOne) SetRoleID(v int) *UserUpdateOne { + _u.mutation.ResetRoleID() + _u.mutation.SetRoleID(v) + return _u +} + +// SetNillableRoleID sets the "role_id" field if the given value is not nil. +func (_u *UserUpdateOne) SetNillableRoleID(v *int) *UserUpdateOne { + if v != nil { + _u.SetRoleID(*v) + } + return _u +} + +// AddRoleID adds value to the "role_id" field. +func (_u *UserUpdateOne) AddRoleID(v int) *UserUpdateOne { + _u.mutation.AddRoleID(v) + return _u +} + +// ClearRoleID clears the value of the "role_id" field. +func (_u *UserUpdateOne) ClearRoleID() *UserUpdateOne { + _u.mutation.ClearRoleID() + return _u +} + // SetDept sets the "dept" field. func (_u *UserUpdateOne) SetDept(v string) *UserUpdateOne { _u.mutation.SetDept(v) @@ -595,6 +658,15 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { if value, ok := _u.mutation.Role(); ok { _spec.SetField(user.FieldRole, field.TypeString, value) } + if value, ok := _u.mutation.RoleID(); ok { + _spec.SetField(user.FieldRoleID, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedRoleID(); ok { + _spec.AddField(user.FieldRoleID, field.TypeInt, value) + } + if _u.mutation.RoleIDCleared() { + _spec.ClearField(user.FieldRoleID, field.TypeInt) + } if value, ok := _u.mutation.Dept(); ok { _spec.SetField(user.FieldDept, field.TypeString, value) } diff --git a/bj_power_wms/etc/bj_power_wms-api-verify.yaml b/bj_power_wms/etc/bj_power_wms-api-verify.yaml new file mode 100644 index 0000000..19a9464 --- /dev/null +++ b/bj_power_wms/etc/bj_power_wms-api-verify.yaml @@ -0,0 +1,29 @@ +Name: bj_power_wms +Host: 0.0.0.0 +Port: 8902 +Timeout: 10000 + +# PostgreSQL +Postgres: + Host: 127.0.0.1 + Port: 5432 + User: postgres + Password: postgres + DBName: bj_power_wms + SSLMode: disable + +# JWT +Auth: + AccessSecret: Hardman_2026 + AccessExpire: 1800 + +Internal: + Token: Hardman_2026 + +Log: + Mode: console + Level: info + +Redis: + Host: 127.0.0.1:6379 + Type: node \ No newline at end of file diff --git a/bj_power_wms/internal/db/db.go b/bj_power_wms/internal/db/db.go index 1af2451..6e801c7 100644 --- a/bj_power_wms/internal/db/db.go +++ b/bj_power_wms/internal/db/db.go @@ -12,6 +12,9 @@ import ( _ "github.com/jackc/pgx/v5/stdlib" ) +// rawDB 持有底层 *sql.DB,供迁移期清理孤儿表(如已下线的 package_boxes)使用 +var rawDB *sql.DB + // MustNewDB 创建 Ent 客户端并验证连接 func MustNewDB(c DatabaseConf) *ent.Client { ec, err := NewDB(c) @@ -35,6 +38,7 @@ func NewDB(c DatabaseConf) (*ent.Client, error) { return nil, fmt.Errorf("ping db: %w", err) } + rawDB = db drv := entsql.OpenDB(dialect.Postgres, db) return ent.NewClient(ent.Driver(drv)), nil } @@ -73,6 +77,15 @@ func AutoMigrate(client *ent.Client) error { if err := client.Schema.Create(ctx); err != nil { return fmt.Errorf("自动迁移失败: %w", err) } + // 清理历史独立装箱表:装箱已合并到统一的出库主表 OutboundOrder, + // 原 package_boxes 表成为孤儿表,此处幂等删除(DROP TABLE IF EXISTS 可重复执行)。 + if rawDB != nil { + if _, err := rawDB.ExecContext(ctx, "DROP TABLE IF EXISTS package_boxes"); err != nil { + slog.Warn("清理旧装箱表 package_boxes 失败(可忽略): " + err.Error()) + } else { + slog.Info("已清理旧装箱表 package_boxes") + } + } slog.Info("数据库迁移完成") return nil } diff --git a/bj_power_wms/internal/handler/auth.go b/bj_power_wms/internal/handler/auth.go index 53c2eee..893398c 100644 --- a/bj_power_wms/internal/handler/auth.go +++ b/bj_power_wms/internal/handler/auth.go @@ -69,7 +69,8 @@ func loginHandler(ctx *svc.ServiceContext) http.HandlerFunc { "expireAt": expireAt, "user": map[string]any{ "id": u.ID, "username": u.Username, "realName": u.RealName, - "role": u.Role, "dept": u.Dept, "permissionCodes": permissionsForRole(u.Role), + "role": u.Role, "roleId": u.RoleID, "dept": u.Dept, + "permissionCodes": permissionsForUser(ctx, u), }, }) } diff --git a/bj_power_wms/internal/handler/excel.go b/bj_power_wms/internal/handler/excel.go index e6c2a62..12bb296 100644 --- a/bj_power_wms/internal/handler/excel.go +++ b/bj_power_wms/internal/handler/excel.go @@ -1,25 +1,176 @@ package handler import ( + "bytes" "fmt" "net/http" + "net/url" "strings" + "time" + "unicode/utf8" "bj_power_wms/ent/inventory" "bj_power_wms/ent/material" "bj_power_wms/internal/svc" + "github.com/google/uuid" "github.com/xuri/excelize/v2" ) -// excelInboundHandler Excel 批量导入入库(结构件) -// 列头(第一行忽略):物料编码 | 批次号(可空,自动生成) | 数量 | 生产日期 | 供应商 | 区域 | 备注 +// xlsxColumn 导出列定义:列名 + 取值函数(返回字符串) +type xlsxColumn struct { + Title string + Get func(map[string]any) string +} + +// xlsxFilename 生成导出文件名:{页面名}_{YYYYMMDDHHMMSS}.xlsx(URL 安全,避免中文编码问题) +func xlsxFilename(page string) string { + return fmt.Sprintf("%s_%s.xlsx", page, time.Now().Format("20060102_150405")) +} + +// sendExcel 用 excelize 生成 .xlsx 并写回响应(UTF-8 表头,列宽自适应,冻结首行) +// headers 与 rows 为字符串二维数组;filename 用于 Content-Disposition。 +func sendExcel(w http.ResponseWriter, filename string, headers []string, rows [][]any /* any: string|int|int64 */) { + buf, err := buildXlsx(headers, rows) + if err != nil { + fail(w, http.StatusInternalServerError, "生成 Excel 失败: "+err.Error()) + return + } + // RFC 5987:中文文件名用 filename*=UTF-8''...(URL 编码),并提供 ASCII 兜底文件名 + asciiName := "export.xlsx" + encName := "" + if utf8.ValidString(filename) { + asciiName = strings.TrimSuffix(filename, ".xlsx") + ".xlsx" + encName = "filename*=UTF-8''" + url.QueryEscape(filename) + } + w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + cd := fmt.Sprintf("attachment; filename=\"%s\"", asciiName) + if encName != "" { + cd += "; " + encName + } + w.Header().Set("Content-Disposition", cd) + w.Header().Set("X-Excel-Filename", url.QueryEscape(filename)) + w.WriteHeader(http.StatusOK) + _, _ = w.Write(buf.Bytes()) +} + +// buildXlsx 生成 xlsx 字节流(含表头样式、列宽自适应) +func buildXlsx(headers []string, rows [][]any) (*bytes.Buffer, error) { + f := excelize.NewFile() + defer f.Close() + sheet := f.GetSheetName(0) + + for i, h := range headers { + cell, _ := excelize.CoordinatesToCellName(i+1, 1) + _ = f.SetCellValue(sheet, cell, h) + } + style, _ := f.NewStyle(&excelize.Style{ + Font: &excelize.Font{Bold: true}, + Fill: excelize.Fill{Type: "pattern", Color: []string{"D9E1F2"}, Pattern: 1}, + Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"}, + }) + _ = f.SetRowStyle(sheet, 1, 1, style) + + for r, row := range rows { + for c, v := range row { + cell, _ := excelize.CoordinatesToCellName(c+1, r+2) + _ = f.SetCellValue(sheet, cell, v) + } + } + + // 列宽按显示宽度估算(中文=2,ASCII=1,宁宽勿窄) + widths := make([]float64, len(headers)) + for c := range headers { + widths[c] = float64(displayWidth(headers[c]) + 2) + } + for _, row := range rows { + for c, v := range row { + if c >= len(widths) { + break + } + cw := float64(displayWidth(fmt.Sprintf("%v", v)) + 2) + if cw > widths[c] { + widths[c] = cw + } + } + } + for c, wd := range widths { + col, _ := excelize.ColumnNumberToName(c + 1) + _ = f.SetColWidth(sheet, col, col, wd) + } + + return f.WriteToBuffer() +} + +// displayWidth 估算字符串在 Excel 中的显示宽度(中文=2,ASCII=1) +func displayWidth(s string) int { + n := 0 + for _, r := range s { + if r > 0x2E7F { // 含中文/全角 + n += 2 + } else { + n++ + } + } + return n +} + +// manageModeLabel 管理粒度中文名:1=结构件 2=精密件 +func manageModeLabel(m int) string { + if m == 1 { + return "结构件" + } + if m == 2 { + return "精密件" + } + return "-" +} + +// unixFmt 把 unix 秒转成 yyyy-MM-dd HH:mm:ss(时间戳<=0 返回空串) +func unixFmt(ts int64) string { + if ts <= 0 { + return "" + } + return time.Unix(ts, 0).Format("2006-01-02 15:04:05") +} + +// inspectionTypeLabel 检验类型中文名 +func inspectionTypeLabel(t string) string { + switch t { + case "incoming": + return "来料检" + case "process": + return "过程检" + case "finished": + return "成品检" + } + return t +} + +// importErr 单行校验错误(行号 + 物料 + 原因),用于"全失败"时回给前端定位 +type importErr struct { + Row int `json:"row"` + MaterialCode string `json:"materialCode"` + Message string `json:"message"` +} + +// excelInboundHandler Excel 批量导入入库 +// mode=batch(结构件):列头(首行忽略) 物料编码 | 批次号(可空自动生成) | 数量 | 生产日期 | 供应商 | 区域 | 备注 +// mode=sn(精密件): 列头(首行忽略) 物料编码 | SN | 区域 | 生产日期 | 供应商 +// +// 强约束:全成功或全失败(一次性全导入 or 全失败,禁止部分成功)。 +// 流程:阶段1 逐行解析+校验(物料存在/数量>0/SN不重复/区域必填) → 任一错则整体拒绝并列出错误行(一行不写); +// 阶段2 全部通过 → 开启单事务,整体提交,任一步失败整体回滚。 func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if err := r.ParseMultipartForm(20 << 20); err != nil { fail(w, http.StatusBadRequest, "文件上传失败: "+err.Error()) return } + mode := r.FormValue("mode") + if mode != "sn" { + mode = "batch" + } f, _, err := r.FormFile("file") if err != nil { fail(w, http.StatusBadRequest, "缺少 file 字段") @@ -39,17 +190,27 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { fail(w, http.StatusBadRequest, "读取工作表失败: "+err.Error()) return } - - type resultRow struct { - Row int `json:"row"` - Code string `json:"materialCode"` - BatchNo string `json:"batchNo"` - Qty int `json:"quantity"` - Error string `json:"error,omitempty"` + if len(rows) <= 1 { + fail(w, http.StatusBadRequest, "文件无数据行(首行为表头,需至少一行数据)") + return } - results := []resultRow{} - success := 0 + type planRow struct { + row int + code string + batchNo string + sn string + qty int + prodDate string + supplier string + zone string + remark string + } + plans := make([]planRow, 0, len(rows)-1) + errs := make([]importErr, 0) + + // ---- 阶段1:解析 + 校验(不落库) ---- + snSeen := map[string]bool{} for i, row := range rows { if i == 0 { continue // 表头 @@ -60,75 +221,184 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { } return "" } - code := cell(0) - batchNo := cell(1) - qtyStr := cell(2) - qty := atoi(qtyStr, 0) - prodDate := cell(3) - supplier := cell(4) - zone := cell(5) - remark := cell(6) + pr := planRow{row: i + 1} + pr.code = cell(0) + if mode == "sn" { + pr.sn = cell(1) + pr.zone = cell(2) // 精密件模板: 物料编码|SN|区域|生产日期|供应商 + pr.prodDate = cell(3) + pr.supplier = cell(4) + pr.remark = cell(4) + } else { + pr.batchNo = cell(1) + pr.qty = atoi(cell(2), 0) + pr.prodDate = cell(3) + pr.supplier = cell(4) + pr.zone = cell(5) // 结构件模板: 物料编码|批次号|数量|生产日期|供应商|区域|备注 + pr.remark = cell(6) + } - res := resultRow{Row: i + 1, Code: code, BatchNo: batchNo, Qty: qty} - - switch { - case code == "": - res.Error = "物料编码为空" - case qty <= 0: - res.Error = "数量必须大于 0" - default: - m, err := ctx.EntClient.Material.Query(). - Where(material.CodeEQ(code)).Only(ctx0()) - if err != nil { - res.Error = "物料不存在" - } else if m.ManageMode == 2 { - res.Error = "精密件请使用 SN 扫码入库,不支持 Excel 导入" - } else { - if batchNo == "" { - batchNo = genBatchNo(code) + if pr.code == "" { + errs = append(errs, importErr{pr.row, pr.code, "物料编码为空"}) + continue + } + m, e := ctx.EntClient.Material.Query().Where(material.CodeEQ(pr.code)).Only(ctx0()) + if e != nil { + errs = append(errs, importErr{pr.row, pr.code, "物料不存在"}) + continue + } + if mode == "sn" { + if m.ManageMode != 2 { + errs = append(errs, importErr{pr.row, pr.code, "该物料为结构件,SN 导入仅支持精密件(按 SN 管理)"}) + continue } - // 同批次追加或新建 - existing, err := ctx.EntClient.Inventory.Query(). - Where(inventory.ManageModeEQ(1), inventory.BatchNoEQ(batchNo)).Only(ctx0()) - if err == nil { - ctx.EntClient.Inventory.UpdateOneID(existing.ID). - AddQuantity(qty). - SetNillableSupplier(strPtr(supplier)). - ExecX(ctx0()) - } else { - ctx.EntClient.Inventory.Create(). - SetManageMode(1). - SetBatchNo(batchNo). - SetMaterialCode(code). - SetNillableMaterialName(strPtr(m.Name)). - SetQuantity(qty). - SetLockedQty(0). - SetNillableProductionDate(strPtr(prodDate)). - SetNillableSupplier(strPtr(supplier)). - SetQualityStatus("未检"). - SetNillableZoneCode(strPtr(zone)). - SetStatus("在库"). - SaveX(ctx0()) + if pr.sn == "" { + errs = append(errs, importErr{pr.row, pr.code, "SN 为空"}) + continue } - inboundNo := "IB" + nowStr() + fmt.Sprintf("%03d", i) - ctx.EntClient.InboundOrder.Create(). - SetInboundNo(inboundNo). - SetNillableInboundType(strPtr("purchase")). - SetMaterialCode(code). - SetNillableMaterialName(strPtr(m.Name)). - SetManageMode(1). - SetNillableZoneCode(strPtr(zone)). - SetQuantity(qty). - SetNillableRemark(strPtr(remark)). - SetOperator("excel-import"). - SaveX(ctx0()) - res.BatchNo = batchNo - success++ + if snSeen[pr.sn] { + errs = append(errs, importErr{pr.row, pr.code, "SN 在文件中重复: "+pr.sn}) + continue + } + snSeen[pr.sn] = true + exists, _ := ctx.EntClient.Inventory.Query(). + Where(inventory.ManageModeEQ(2), inventory.SnCodeEQ(pr.sn)).Exist(ctx0()) + if exists { + errs = append(errs, importErr{pr.row, pr.code, "SN 已存在: "+pr.sn}) + continue + } + } else { + if m.ManageMode != 1 { + errs = append(errs, importErr{pr.row, pr.code, "该物料为精密件,请使用 SN 导入"}) + continue + } + if pr.qty <= 0 { + errs = append(errs, importErr{pr.row, pr.code, "数量必须大于 0"}) + continue } } - results = append(results, res) + if pr.zone == "" { + errs = append(errs, importErr{pr.row, pr.code, "区域为空(必填)"}) + continue + } + plans = append(plans, pr) } - ok(w, map[string]any{"total": len(results), "success": success, "rows": results}) + // ---- 阶段2:有错则整体拒绝,一行都不写 ---- + if len(errs) > 0 { + ok(w, map[string]any{"success": 0, "failed": len(errs), "errors": errs}) + return + } + + // ---- 阶段3:全部通过 → 单事务整体提交(原子,全成功或全失败) ---- + tx, e := ctx.EntClient.Tx(ctx0()) + if e != nil { + fail(w, http.StatusInternalServerError, "开启事务失败: "+e.Error()) + return + } + committed := false + defer func() { + if !committed { + _ = tx.Rollback() + } + }() + + for _, pr := range plans { + inboundNo := "IB" + uuid.NewString()[:12] + m, _ := tx.Material.Query().Where(material.CodeEQ(pr.code)).Only(ctx0()) + if mode == "sn" { + if _, e = tx.Inventory.Create(). + SetManageMode(2). + SetMaterialCode(pr.code). + SetNillableMaterialName(strPtr(m.Name)). + SetSnCode(pr.sn). + SetQuantity(1).SetLockedQty(0). + SetQualityStatus("未检"). + SetNillableProductionDate(strPtr(pr.prodDate)). + SetNillableSupplier(strPtr(pr.supplier)). + SetNillableZoneCode(strPtr(pr.zone)). + SetStatus("在库"). + SetInboundNo(inboundNo). + Save(ctx0()); e != nil { + fail(w, http.StatusInternalServerError, "创建 SN 库存失败: "+e.Error()) + return + } + if _, e = tx.InboundDetail.Create(). + SetInboundNo(inboundNo).SetSnCode(pr.sn).SetMaterialCode(pr.code).SetQuantity(1). + Save(ctx0()); e != nil { + fail(w, http.StatusInternalServerError, "创建入库明细失败: "+e.Error()) + return + } + } else { + batchNo := pr.batchNo + if batchNo == "" { + // 同一导入内多行空批次需保证批次号唯一,追加行号后缀 + batchNo = genBatchNo(pr.code) + fmt.Sprintf("-%d", pr.row) + } + existing, e2 := tx.Inventory.Query(). + Where(inventory.ManageModeEQ(1), inventory.BatchNoEQ(batchNo)).Only(ctx0()) + if e2 == nil { + if _, e = tx.Inventory.UpdateOneID(existing.ID). + AddQuantity(pr.qty). + SetNillableSupplier(strPtr(pr.supplier)). + Save(ctx0()); e != nil { + fail(w, http.StatusInternalServerError, "追加批次失败: "+e.Error()) + return + } + } else { + if _, e = tx.Inventory.Create(). + SetManageMode(1). + SetBatchNo(batchNo). + SetMaterialCode(pr.code). + SetNillableMaterialName(strPtr(m.Name)). + SetQuantity(pr.qty).SetLockedQty(0). + SetNillableProductionDate(strPtr(pr.prodDate)). + SetNillableSupplier(strPtr(pr.supplier)). + SetQualityStatus("未检"). + SetNillableZoneCode(strPtr(pr.zone)). + SetStatus("在库"). + SetInboundNo(inboundNo). + Save(ctx0()); e != nil { + fail(w, http.StatusInternalServerError, "创建库存失败: "+e.Error()) + return + } + } + if _, e = tx.InboundDetail.Create(). + SetInboundNo(inboundNo).SetBatchNo(batchNo).SetMaterialCode(pr.code).SetQuantity(pr.qty). + Save(ctx0()); e != nil { + fail(w, http.StatusInternalServerError, "创建入库明细失败: "+e.Error()) + return + } + } + if _, e = tx.InboundOrder.Create(). + SetInboundNo(inboundNo). + SetNillableInboundType(strPtr("purchase")). + SetMaterialCode(pr.code). + SetNillableMaterialName(strPtr(m.Name)). + SetManageMode(m.ManageMode). + SetNillableZoneCode(strPtr(pr.zone)). + SetQuantity(ternary(mode == "sn", 1, pr.qty)). + SetNillableRemark(strPtr(pr.remark)). + SetOperator("excel-import"). + Save(ctx0()); e != nil { + fail(w, http.StatusInternalServerError, "创建入库单失败: "+e.Error()) + return + } + } + + if e = tx.Commit(); e != nil { + fail(w, http.StatusInternalServerError, "提交事务失败: "+e.Error()) + return + } + committed = true + ok(w, map[string]any{"success": len(plans), "failed": 0, "errors": []importErr{}}) } } + +// ternary 小工具:condition 为真返回 a,否则 b +func ternary(cond bool, a, b int) int { + if cond { + return a + } + return b +} diff --git a/bj_power_wms/internal/handler/inbound.go b/bj_power_wms/internal/handler/inbound.go index 19300e6..ad3ae90 100644 --- a/bj_power_wms/internal/handler/inbound.go +++ b/bj_power_wms/internal/handler/inbound.go @@ -2,6 +2,7 @@ package handler import ( "net/http" + "time" "bj_power_wms/ent" "bj_power_wms/ent/inbounddetail" @@ -215,59 +216,172 @@ func createInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { // excelInboundHandler 实现见 excel.go -// queryInboundHandler 入库单查询 +// inboundRow 列表/导出统一结构:入库单 + 明细总数。 +// 注意:明细(批次/SN)不在此内嵌——精密件单可能上万条 SN, +// 列表查询若一次性加载全部明细会撑爆内存,故只带总数,明细按需分页加载。 +type inboundRow struct { + *ent.InboundOrder + DetailCount int `json:"detailCount"` +} + +// applyInboundFilters 统一列表与导出的筛选条件 +// 结构件(manageMode=1)与精密件(manageMode=2)同主表(inbound_order),按 manageMode 区分类型 +func applyInboundFilters(q *ent.InboundOrderQuery, r *http.Request) *ent.InboundOrderQuery { + if v := r.URL.Query().Get("inboundNo"); v != "" { + q = q.Where(inboundorder.InboundNoContains(v)) + } + if v := r.URL.Query().Get("materialCode"); v != "" { + q = q.Where(inboundorder.MaterialCodeContains(v)) + } + if v := r.URL.Query().Get("manageMode"); v != "" { + if m := atoi(v, 0); m != 0 { + q = q.Where(inboundorder.ManageModeEQ(m)) + } + } + if v := r.URL.Query().Get("inboundType"); v != "" { + q = q.Where(inboundorder.InboundTypeEQ(v)) + } + if v := r.URL.Query().Get("keyword"); v != "" { + kw := v + q = q.Where(inboundorder.Or( + inboundorder.MaterialCodeContains(kw), + inboundorder.InboundNoContains(kw), + inboundorder.MaterialNameContains(kw), + )) + } + if v := r.URL.Query().Get("startDate"); v != "" { + if t, err := time.ParseInLocation("2006-01-02", v, time.Local); err == nil { + q = q.Where(inboundorder.CreatedAtGTE(t.Unix())) + } + } + if v := r.URL.Query().Get("endDate"); v != "" { + if t, err := time.ParseInLocation("2006-01-02", v, time.Local); err == nil { + // 含当天全天 + q = q.Where(inboundorder.CreatedAtLTE(t.Add(24 * time.Hour).Unix())) + } + } + return q +} + +// buildInboundRows 仅组装入库单 + 各单明细总数(count,代价极低,不加载明细内容) +func buildInboundRows(ctx *svc.ServiceContext, list []*ent.InboundOrder) []inboundRow { + rows := make([]inboundRow, 0, len(list)) + for _, ib := range list { + cnt, _ := ctx.EntClient.InboundDetail.Query(). + Where(inbounddetail.InboundNoEQ(ib.InboundNo)).Count(ctx0()) + rows = append(rows, inboundRow{ib, cnt}) + } + return rows +} + +// inboundDetailsHandler 入库单明细分页查询(批次/SN)。 +// 单独接口、按需加载、分页返回——避免一次拉取上万条 SN 撑爆内存/前端。 +// 参数:inboundNo(必填) page pageSize(默认 50) +func inboundDetailsHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + inboundNo := r.URL.Query().Get("inboundNo") + if inboundNo == "" { + fail(w, http.StatusBadRequest, "inboundNo 必填") + return + } + page := atoi(r.URL.Query().Get("page"), 1) + pageSize := atoi(r.URL.Query().Get("pageSize"), 50) + if page < 1 { + page = 1 + } + if pageSize < 1 || pageSize > 500 { + pageSize = 50 + } + q := ctx.EntClient.InboundDetail.Query(). + Where(inbounddetail.InboundNoEQ(inboundNo)) + total, err := q.Count(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + list, err := q.Order(ent.Desc("created_at")). + Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + ok(w, map[string]any{ + "total": total, + "list": list, + "page": page, + "pageSize": pageSize, + }) + } +} + +// queryInboundHandler 入库单查询(分页列表) +// 结构件/精密件同主表,默认返回全部;支持多条件筛选。 func queryInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { page := atoi(r.URL.Query().Get("page"), 1) pageSize := atoi(r.URL.Query().Get("pageSize"), 20) - materialCode := r.URL.Query().Get("materialCode") - inboundType := r.URL.Query().Get("inboundType") - inboundNo := r.URL.Query().Get("inboundNo") - + if page < 1 { + page = 1 + } + if pageSize < 1 { + pageSize = 20 + } q := ctx.EntClient.InboundOrder.Query() - if materialCode != "" { - q = q.Where(inboundorder.MaterialCodeEQ(materialCode)) - } - if inboundType != "" { - q = q.Where(inboundorder.InboundTypeEQ(inboundType)) - } - if inboundNo != "" { - q = q.Where(inboundorder.InboundNoEQ(inboundNo)) - } + q = applyInboundFilters(q, r) total, err := q.Count(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) return } - type row struct { - *ent.InboundOrder - Details []*ent.InboundDetail `json:"details"` - } - rows := make([]row, 0, len(list)) - for _, ib := range list { - details, _ := ctx.EntClient.InboundDetail.Query(). - Where(inbounddetail.InboundNoEQ(ib.InboundNo)). - All(ctx0()) - rows = append(rows, row{ib, details}) - } - ok(w, map[string]any{ "total": total, - "list": rows, + "list": buildInboundRows(ctx, list), "page": page, "pageSize": pageSize, }) } } +// exportInboundHandler 入库单导出:按筛选条件返回全部(不分页),前端转 CSV, +// 与 /api/outbound/export 保持一致。 +func exportInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + q := ctx.EntClient.InboundOrder.Query() + q = applyInboundFilters(q, r) + list, err := q.Order(ent.Desc("created_at")).All(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + rows := buildInboundRows(ctx, list) + // xlsx 导出:格式化 = xlsx → 直接生成二进制文件;否则保持 JSON 兼容 + if r.URL.Query().Get("format") == "xlsx" { + headers := []string{"入库单号", "物料编码", "物料名称", "类型", "数量", "区域", "操作人", "备注", "明细条数", "入库时间"} + matrix := make([][]any, 0, len(rows)) + for _, row := range rows { + ib := row.InboundOrder + matrix = append(matrix, []any{ + ib.InboundNo, ib.MaterialCode, ib.MaterialName, + manageModeLabel(ib.ManageMode), ib.Quantity, ib.ZoneCode, + ib.Operator, ib.Remark, row.DetailCount, + unixFmt(ib.CreatedAt), + }) + } + sendExcel(w, xlsxFilename("入库管理"), headers, matrix) + return + } + ok(w, map[string]any{"total": len(rows), "list": rows}) + } +} + // genBatchNo 生成批次号:日期 + 自增 func genBatchNo(materialCode string) string { // TODO: 使用数据库序列或 Redis INCR 保证自增唯一 diff --git a/bj_power_wms/internal/handler/inspection.go b/bj_power_wms/internal/handler/inspection.go index 19f37bf..324962f 100644 --- a/bj_power_wms/internal/handler/inspection.go +++ b/bj_power_wms/internal/handler/inspection.go @@ -1,7 +1,9 @@ package handler import ( + "fmt" "net/http" + "time" "bj_power_wms/ent" "bj_power_wms/ent/inspectionrecord" @@ -11,8 +13,25 @@ import ( "github.com/zeromicro/go-zero/core/logx" ) +// resolveInspectionTarget 通过编号(批次号或 SN)定位唯一库存行。 +// 检验必须落在真实存在的库存记录上,才能同步质量状态——杜绝"提示成功但库存未更新"的假闭环。 +// 返回错误或定位到的库存行(含物料编码与管理粒度,供后续写入检验记录与翻状态使用)。 +func resolveInspectionTarget(ctx *svc.ServiceContext, targetId string) (*ent.Inventory, error) { + // 优先按批次号(结构件) + if inv, err := ctx.EntClient.Inventory.Query(). + Where(inventory.ManageModeEQ(1), inventory.BatchNoEQ(targetId)).Only(ctx0()); err == nil { + return inv, nil + } + // 再按 SN(精密件) + if inv, err := ctx.EntClient.Inventory.Query(). + Where(inventory.ManageModeEQ(2), inventory.SnCodeEQ(targetId)).Only(ctx0()); err == nil { + return inv, nil + } + return nil, fmt.Errorf("未找到对应库存记录(批次号/SN):%s,请确认编号是否已入库、或该记录是否已出库", targetId) +} + // createInspectionHandler 创建检验记录 -// body: { targetType: BATCH/SN, targetId, materialCode, inspectionType, status, resultValue, inspector } +// body: { targetType: BATCH/SN, targetId, status, inspector } // 同步库存检验状态:BATCH → inventory(manage_mode=1, batch_no);SN → inventory(manage_mode=2, sn_code) func createInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -23,6 +42,10 @@ func createInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { InspectionType string `json:"inspectionType"` Status string `json:"status"` // 合格/不合格 ResultValue string `json:"resultValue"` + InspectQty int `json:"inspectQty"` // 检验数量 + PassQty int `json:"passQty"` // 合格数量 + CheckDesc string `json:"checkDesc"` // 检测说明 + FailReason string `json:"failReason"` // 不合格原因 Inspector string `json:"inspector"` Remark string `json:"remark"` } @@ -39,6 +62,19 @@ func createInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { return } + // 定位真实库存行:自动按 批次号/SN 解析(前端选错类型也能正确命中) + inv, err := resolveInspectionTarget(ctx, req.TargetId) + if err != nil { + fail(w, http.StatusBadRequest, err.Error()) + return + } + // 物料编码必填字段由库存行回填,杜绝 missing required field + req.MaterialCode = inv.MaterialCode + req.TargetType = "BATCH" + if inv.ManageMode == 2 { + req.TargetType = "SN" + } + tx, err := ctx.EntClient.Tx(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, "开启事务失败: "+err.Error()) @@ -58,6 +94,10 @@ func createInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { SetInspectionType(req.InspectionType). SetStatus(req.Status). SetNillableResultValue(strPtr(req.ResultValue)). + SetInspectQty(req.InspectQty). + SetPassQty(req.PassQty). + SetNillableCheckDesc(strPtr(req.CheckDesc)). + SetNillableFailReason(strPtr(req.FailReason)). SetNillableInspector(strPtr(req.Inspector)). SetNillableRemark(strPtr(req.Remark)). Save(ctx0()) @@ -66,17 +106,9 @@ func createInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { return } - // 同步库存检验状态 - q := tx.Inventory.Update() - if req.TargetType == "BATCH" { - q = q.Where(inventory.ManageModeEQ(1), inventory.BatchNoEQ(req.TargetId)) - } else if req.TargetType == "SN" { - q = q.Where(inventory.ManageModeEQ(2), inventory.SnCodeEQ(req.TargetId)) - } else { - fail(w, http.StatusBadRequest, "targetType 只支持 BATCH/SN") - return - } - if _, err = q.SetQualityStatus(req.Status).Save(ctx0()); err != nil { + // 同步库存检验状态:直接更新定位到的那条库存行(精确,绝不误伤) + if _, err = tx.Inventory.UpdateOneID(inv.ID). + SetQualityStatus(req.Status).Save(ctx0()); err != nil { fail(w, http.StatusInternalServerError, "同步库存检验状态失败: "+err.Error()) return } @@ -100,6 +132,10 @@ func batchFlipInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { TargetType string `json:"targetType"` TargetIds []string `json:"targetIds"` Status string `json:"status"` + InspectQty int `json:"inspectQty"` // 检验数量 + PassQty int `json:"passQty"` // 合格数量 + CheckDesc string `json:"checkDesc"` // 检测说明 + FailReason string `json:"failReason"` // 不合格原因 Inspector string `json:"inspector"` } if err := parseJSON(r, &req); err != nil { @@ -111,6 +147,27 @@ func batchFlipInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { return } + // 预校验:所有编号必须能定位到库存行,任意一条找不到则整体拒绝(避免部分成功、假闭环) + type target struct { + id string + inv *ent.Inventory + targetType string + material string + } + targets := make([]target, 0, len(req.TargetIds)) + for _, id := range req.TargetIds { + inv, err := resolveInspectionTarget(ctx, id) + if err != nil { + fail(w, http.StatusBadRequest, err.Error()) + return + } + tt := "BATCH" + if inv.ManageMode == 2 { + tt = "SN" + } + targets = append(targets, target{id: id, inv: inv, targetType: tt, material: inv.MaterialCode}) + } + tx, err := ctx.EntClient.Tx(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, "开启事务失败: "+err.Error()) @@ -124,26 +181,23 @@ func batchFlipInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { }() flipped := 0 - for _, id := range req.TargetIds { + for _, t := range targets { if _, err = tx.InspectionRecord.Create(). - SetTargetType(req.TargetType). - SetTargetID(id). + SetTargetType(t.targetType). + SetTargetID(t.id). + SetMaterialCode(t.material). SetStatus(req.Status). + SetInspectQty(req.InspectQty). + SetPassQty(req.PassQty). + SetNillableCheckDesc(strPtr(req.CheckDesc)). + SetNillableFailReason(strPtr(req.FailReason)). SetNillableInspector(strPtr(req.Inspector)). Save(ctx0()); err != nil { fail(w, http.StatusInternalServerError, "创建检验记录失败: "+err.Error()) return } - q := tx.Inventory.Update() - if req.TargetType == "BATCH" { - q = q.Where(inventory.ManageModeEQ(1), inventory.BatchNoEQ(id)) - } else if req.TargetType == "SN" { - q = q.Where(inventory.ManageModeEQ(2), inventory.SnCodeEQ(id)) - } else { - fail(w, http.StatusBadRequest, "targetType 只支持 BATCH/SN") - return - } - if _, err = q.SetQualityStatus(req.Status).Save(ctx0()); err != nil { + if _, err = tx.Inventory.UpdateOneID(t.inv.ID). + SetQualityStatus(req.Status).Save(ctx0()); err != nil { fail(w, http.StatusInternalServerError, "同步库存检验状态失败: "+err.Error()) return } @@ -169,13 +223,16 @@ func queryInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { materialCode := r.URL.Query().Get("materialCode") inspectionType := r.URL.Query().Get("inspectionType") status := r.URL.Query().Get("status") + inspector := r.URL.Query().Get("inspector") + startDate := r.URL.Query().Get("startDate") + endDate := r.URL.Query().Get("endDate") q := ctx.EntClient.InspectionRecord.Query() if targetId != "" { q = q.Where(inspectionrecord.TargetIDContains(targetId)) } if materialCode != "" { - q = q.Where(inspectionrecord.MaterialCodeEQ(materialCode)) + q = q.Where(inspectionrecord.MaterialCodeContains(materialCode)) } if inspectionType != "" { q = q.Where(inspectionrecord.InspectionTypeEQ(inspectionType)) @@ -183,13 +240,27 @@ func queryInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { if status != "" { q = q.Where(inspectionrecord.StatusEQ(status)) } + if inspector != "" { + q = q.Where(inspectionrecord.InspectorContains(inspector)) + } + // 时间筛选(默认近3个月由前端传入;兼容两端口径) + if startDate != "" { + if t, err := time.ParseInLocation("2006-01-02", startDate, time.Local); err == nil { + q = q.Where(inspectionrecord.CreatedAtGTE(t.Unix())) + } + } + if endDate != "" { + if t, err := time.ParseInLocation("2006-01-02", endDate, time.Local); err == nil { + q = q.Where(inspectionrecord.CreatedAtLTE(t.Add(24 * time.Hour).Unix())) + } + } total, err := q.Count(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) @@ -204,3 +275,72 @@ func queryInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { }) } } + +// exportInspectionHandler 检验记录全量导出(按条件返回全部 JSON,前端转 CSV/Excel) +// GET /api/inspection/export?targetId=&materialCode=&inspectionType=&status=&inspector=&startDate=&endDate= +func exportInspectionHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + targetId := r.URL.Query().Get("targetId") + materialCode := r.URL.Query().Get("materialCode") + inspectionType := r.URL.Query().Get("inspectionType") + status := r.URL.Query().Get("status") + inspector := r.URL.Query().Get("inspector") + startDate := r.URL.Query().Get("startDate") + endDate := r.URL.Query().Get("endDate") + + q := ctx.EntClient.InspectionRecord.Query() + if targetId != "" { + q = q.Where(inspectionrecord.TargetIDContains(targetId)) + } + if materialCode != "" { + q = q.Where(inspectionrecord.MaterialCodeContains(materialCode)) + } + if inspectionType != "" { + q = q.Where(inspectionrecord.InspectionTypeEQ(inspectionType)) + } + if status != "" { + q = q.Where(inspectionrecord.StatusEQ(status)) + } + if inspector != "" { + q = q.Where(inspectionrecord.InspectorContains(inspector)) + } + if startDate != "" { + if t, err := time.ParseInLocation("2006-01-02", startDate, time.Local); err == nil { + q = q.Where(inspectionrecord.CreatedAtGTE(t.Unix())) + } + } + if endDate != "" { + if t, err := time.ParseInLocation("2006-01-02", endDate, time.Local); err == nil { + q = q.Where(inspectionrecord.CreatedAtLTE(t.Add(24 * time.Hour).Unix())) + } + } + + list, err := q.Order(ent.Desc("created_at")).All(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + // xlsx 导出 + if r.URL.Query().Get("format") == "xlsx" { + headers := []string{"ID", "对象", "批次/SN", "物料编码", "检验类型", "结论", "检验数", "合格数", "检测说明", "不合格原因", "检验员", "备注", "检验时间"} + matrix := make([][]any, 0, len(list)) + for _, rec := range list { + obj := rec.TargetType + if obj == "BATCH" { + obj = "批次" + } else if obj == "SN" { + obj = "SN" + } + matrix = append(matrix, []any{ + rec.ID, obj, rec.TargetID, rec.MaterialCode, + inspectionTypeLabel(rec.InspectionType), rec.Status, + rec.InspectQty, rec.PassQty, rec.CheckDesc, rec.FailReason, + rec.Inspector, rec.Remark, unixFmt(rec.CreatedAt), + }) + } + sendExcel(w, xlsxFilename("检验记录"), headers, matrix) + return + } + ok(w, map[string]any{"list": list}) + } +} diff --git a/bj_power_wms/internal/handler/internalapi.go b/bj_power_wms/internal/handler/internalapi.go index 2d129cd..51f75ff 100644 --- a/bj_power_wms/internal/handler/internalapi.go +++ b/bj_power_wms/internal/handler/internalapi.go @@ -90,7 +90,7 @@ func internalDisplayHandler(ctx *svc.ServiceContext) http.HandlerFunc { snInStock, _ := ctx.EntClient.Inventory.Query().Where(inventory.ManageModeEQ(2), inventory.StatusIn("在库", "锁定")).Count(ctx0()) snOut, _ := ctx.EntClient.Inventory.Query().Where(inventory.ManageModeEQ(2), inventory.StatusEQ("出库")).Count(ctx0()) semiInStock, _ := ctx.EntClient.SemiFinished.Query().Where(semifinished.StatusEQ("在库")).Count(ctx0()) - pkgCount, _ := ctx.EntClient.PackageBox.Query().Count(ctx0()) + pkgCount, _ := ctx.EntClient.OutboundOrder.Query().Where(outboundorder.BoxNoNEQ("")).Count(ctx0()) dayStart := time.Now().Truncate(24 * time.Hour).Unix() inToday, _ := ctx.EntClient.InboundOrder.Query(). diff --git a/bj_power_wms/internal/handler/material.go b/bj_power_wms/internal/handler/material.go index b5db11d..94a88e6 100644 --- a/bj_power_wms/internal/handler/material.go +++ b/bj_power_wms/internal/handler/material.go @@ -2,6 +2,7 @@ package handler import ( "net/http" + "time" "bj_power_wms/ent" "bj_power_wms/ent/material" @@ -117,10 +118,27 @@ func queryMaterialsHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { page := atoi(r.URL.Query().Get("page"), 1) pageSize := atoi(r.URL.Query().Get("pageSize"), 20) - keyword := r.URL.Query().Get("keyword") - templateCode := r.URL.Query().Get("templateCode") + materialCode := r.URL.Query().Get("materialCode") + name := r.URL.Query().Get("name") + spec := r.URL.Query().Get("spec") + manageMode := atoi(r.URL.Query().Get("manageMode"), 0) + startDate := r.URL.Query().Get("startDate") + endDate := r.URL.Query().Get("endDate") + keyword := r.URL.Query().Get("keyword") // 兼容旧版,作为物料编码/名称兜底 q := ctx.EntClient.Material.Query() + if materialCode != "" { + q = q.Where(material.CodeContains(materialCode)) + } + if name != "" { + q = q.Where(material.NameContains(name)) + } + if spec != "" { + q = q.Where(material.SpecContains(spec)) + } + if manageMode != 0 { + q = q.Where(material.ManageModeEQ(manageMode)) + } if keyword != "" { q = q.Where( material.Or( @@ -129,8 +147,15 @@ func queryMaterialsHandler(ctx *svc.ServiceContext) http.HandlerFunc { ), ) } - if templateCode != "" { - q = q.Where(material.TemplateCodeEQ(templateCode)) + if startDate != "" { + if t, err := time.ParseInLocation("2006-01-02", startDate, time.Local); err == nil { + q = q.Where(material.CreatedAtGTE(t.Unix())) + } + } + if endDate != "" { + if t, err := time.ParseInLocation("2006-01-02", endDate, time.Local); err == nil { + q = q.Where(material.CreatedAtLTE(t.Add(24 * time.Hour).Unix())) + } } total, err := q.Count(ctx0()) @@ -139,7 +164,7 @@ func queryMaterialsHandler(ctx *svc.ServiceContext) http.HandlerFunc { return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize). Limit(pageSize). All(ctx0()) @@ -160,7 +185,7 @@ func queryMaterialsHandler(ctx *svc.ServiceContext) http.HandlerFunc { // listMaterialsHandler 下拉框全量列表(不翻页) func listMaterialsHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - list, err := ctx.EntClient.Material.Query().Order(ent.Desc("id")).All(ctx0()) + list, err := ctx.EntClient.Material.Query().Order(ent.Desc("created_at")).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) return diff --git a/bj_power_wms/internal/handler/misc.go b/bj_power_wms/internal/handler/misc.go index 7031137..1e5bdcd 100644 --- a/bj_power_wms/internal/handler/misc.go +++ b/bj_power_wms/internal/handler/misc.go @@ -1,19 +1,17 @@ package handler import ( - "encoding/json" "net/http" "strconv" "strings" "bj_power_wms/ent" "bj_power_wms/ent/ordermaterialledger" - "bj_power_wms/ent/packagebox" "bj_power_wms/ent/semifinished" "bj_power_wms/internal/svc" ) -// 半成品 / 包装 / 台账 相关(盘点见 stocktake.go) +// 半成品 / 台账 相关(盘点见 stocktake.go) // semiInboundHandler 半成品入库(携带已完成工序) // 与 MES 闭环:MES 工位报工暂存退库时调用本接口,把半成品 SN 入 WMS 库。 @@ -139,7 +137,7 @@ func querySemiHandler(ctx *svc.ServiceContext) http.HandlerFunc { fail(w, http.StatusInternalServerError, err.Error()) return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) @@ -155,156 +153,6 @@ func querySemiHandler(ctx *svc.ServiceContext) http.HandlerFunc { } } -// packageBindHandler 装箱绑定(箱号 ↔ SN),支持合同号 -func packageBindHandler(ctx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req struct { - BoxNo string `json:"boxNo"` - SnList []string `json:"snList"` - MaterialCode string `json:"materialCode"` - ContractNo string `json:"contractNo"` - Operator string `json:"operator"` - Remark string `json:"remark"` - } - if err := parseJSON(r, &req); err != nil { - fail(w, http.StatusBadRequest, "参数错误") - return - } - if req.BoxNo == "" || len(req.SnList) == 0 { - fail(w, http.StatusBadRequest, "箱号和 SN 清单必填") - return - } - - exists, err := ctx.EntClient.PackageBox.Query(). - Where(packagebox.BoxNoEQ(req.BoxNo)). - Exist(ctx0()) - if err != nil { - fail(w, http.StatusInternalServerError, err.Error()) - return - } - if exists { - fail(w, http.StatusConflict, "箱号已存在: "+req.BoxNo) - return - } - - // SN 列表序列化 - snJSON := toJSON(req.SnList) - - pkg, err := ctx.EntClient.PackageBox.Create(). - SetBoxNo(req.BoxNo). - SetSnList(snJSON). - SetNillableMaterialCode(strPtr(req.MaterialCode)). - SetQuantity(len(req.SnList)). - SetNillableContractNo(strPtr(req.ContractNo)). - SetNillableOperator(strPtr(req.Operator)). - SetNillableRemark(strPtr(req.Remark)). - Save(ctx0()) - if err != nil { - fail(w, http.StatusInternalServerError, err.Error()) - return - } - ok(w, pkg) - } -} - -// packageUpdateHandler 编辑装箱(重新装箱 SN / 修改合同号等) -func packageUpdateHandler(ctx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req struct { - ID int `json:"id"` - SnList []string `json:"snList"` - MaterialCode string `json:"materialCode"` - ContractNo string `json:"contractNo"` - Operator string `json:"operator"` - Remark string `json:"remark"` - } - if err := parseJSON(r, &req); err != nil || req.ID <= 0 { - fail(w, http.StatusBadRequest, "参数错误") - return - } - upd := ctx.EntClient.PackageBox.UpdateOneID(req.ID) - if len(req.SnList) > 0 { - upd.SetSnList(toJSON(req.SnList)).SetQuantity(len(req.SnList)) - } - upd.SetNillableMaterialCode(strPtr(req.MaterialCode)). - SetNillableContractNo(strPtr(req.ContractNo)). - SetNillableOperator(strPtr(req.Operator)). - SetNillableRemark(strPtr(req.Remark)) - pkg, err := upd.Save(ctx0()) - if err != nil { - fail(w, http.StatusInternalServerError, "更新装箱失败: "+err.Error()) - return - } - ok(w, pkg) - } -} - -// toJSON 序列化任意值为 JSON 字符串 -func toJSON(v any) string { - b, err := json.Marshal(v) - if err != nil { - return "[]" - } - return string(b) -} - -// queryPackageHandler 装箱查询(多条件:箱号/合同号/操作人/物料/时间范围) -func queryPackageHandler(ctx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - boxNo := r.URL.Query().Get("boxNo") - contractNo := r.URL.Query().Get("contractNo") - operator := r.URL.Query().Get("operator") - materialCode := r.URL.Query().Get("materialCode") - startAt := r.URL.Query().Get("startAt") - endAt := r.URL.Query().Get("endAt") - page := atoi(r.URL.Query().Get("page"), 1) - pageSize := atoi(r.URL.Query().Get("pageSize"), 20) - - q := ctx.EntClient.PackageBox.Query() - if boxNo != "" { - q = q.Where(packagebox.BoxNoContains(boxNo)) - } - if contractNo != "" { - q = q.Where(packagebox.ContractNoContains(contractNo)) - } - if operator != "" { - q = q.Where(packagebox.OperatorContains(operator)) - } - if materialCode != "" { - q = q.Where(packagebox.MaterialCodeEQ(materialCode)) - } - if startAt != "" { - start := atoi64(startAt, 0) - if start > 0 { - q = q.Where(packagebox.CreatedAtGTE(start)) - } - } - if endAt != "" { - end := atoi64(endAt, 0) - if end > 0 { - q = q.Where(packagebox.CreatedAtLTE(end)) - } - } - total, err := q.Count(ctx0()) - if err != nil { - fail(w, http.StatusInternalServerError, err.Error()) - return - } - list, err := q.Order(ent.Desc("id")). - Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) - if err != nil { - fail(w, http.StatusInternalServerError, err.Error()) - return - } - ok(w, map[string]any{ - "total": total, - "list": list, - "page": page, - "pageSize": pageSize, - }) - } -} - // ledger 相关:queryLedgerHandler 工单物料台账查询 func queryLedgerHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -325,7 +173,7 @@ func queryLedgerHandler(ctx *svc.ServiceContext) http.HandlerFunc { fail(w, http.StatusInternalServerError, err.Error()) return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) diff --git a/bj_power_wms/internal/handler/orders.go b/bj_power_wms/internal/handler/orders.go index 14d0a89..c0e08a9 100644 --- a/bj_power_wms/internal/handler/orders.go +++ b/bj_power_wms/internal/handler/orders.go @@ -29,26 +29,29 @@ func ordersHandler(ctx *svc.ServiceContext) http.HandlerFunc { url := ctx.Config.Mes.BaseURL + "/api/internal/order/query?orderNo=" + r.URL.Query().Get("orderNo") req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { - fail(w, http.StatusBadGateway, "构造 MES 请求失败") + // 构造请求都失败属代码级异常,返回空列表让备料出库页可降级(仍可手输工单号) + ok(w, []mesOrder{}) return } req.Header.Set("X-API-TOKEN", ctx.Config.Mes.Token) cli := &http.Client{Timeout: 5 * time.Second} resp, err := cli.Do(req) if err != nil { - fail(w, http.StatusBadGateway, "无法连接 MES 服务") + // MES 未启用/不可达:优雅降级为空列表,不抛 502 打断备料出库页 + // (用户仍可在 prep 页直接手输工单号查询台账;非 MES 场景请用「通用出库」) + ok(w, []mesOrder{}) return } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - fail(w, http.StatusBadGateway, "MES 返回异常") + ok(w, []mesOrder{}) return } var body struct { Data []mesOrder `json:"data"` } if err := json.NewDecoder(resp.Body).Decode(&body); err != nil { - fail(w, http.StatusBadGateway, "解析 MES 响应失败") + ok(w, []mesOrder{}) return } list := body.Data diff --git a/bj_power_wms/internal/handler/outbound.go b/bj_power_wms/internal/handler/outbound.go index 07b196d..0f2c97e 100644 --- a/bj_power_wms/internal/handler/outbound.go +++ b/bj_power_wms/internal/handler/outbound.go @@ -1,7 +1,9 @@ package handler import ( + "encoding/json" "net/http" + "strings" "bj_power_wms/ent" "bj_power_wms/ent/inventory" @@ -60,7 +62,7 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc { ). Only(ctx0()) if err != nil { - fail(w, http.StatusBadRequest, "工单物料台账不存在,请先同步工单 BOM: "+req.OrderNo+"/"+req.MaterialCode) + fail(w, http.StatusBadRequest, "工单物料台账不存在,请先在 MES 同步工单 BOM 后再领料;如无需挂靠工单(退料/样品/报废/发货),请改用「通用出库」: "+req.OrderNo+"/"+req.MaterialCode) return } if ledger.Status == "领料完结" { @@ -237,6 +239,7 @@ func queryOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { orderNo := r.URL.Query().Get("orderNo") materialCode := r.URL.Query().Get("materialCode") outboundNo := r.URL.Query().Get("outboundNo") + boxNo := r.URL.Query().Get("boxNo") q := ctx.EntClient.OutboundOrder.Query() if orderNo != "" { @@ -248,13 +251,16 @@ func queryOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { if outboundNo != "" { q = q.Where(outboundorder.OutboundNoEQ(outboundNo)) } + if boxNo != "" { + q = q.Where(outboundorder.BoxNoContains(boxNo)) + } total, err := q.Count(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) @@ -283,6 +289,259 @@ func queryOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { } } +// generalOutboundRequest 通用出库请求(不依赖 MES 工单) +type generalOutboundRequest struct { + MaterialCode string `json:"materialCode"` + BatchNo string `json:"batchNo"` + SnList []string `json:"snList"` + Qty int `json:"qty"` + Operator string `json:"operator"` + ZoneCode string `json:"zoneCode"` + BoxNo string `json:"boxNo"` + ContractNo string `json:"contractNo"` + Remark string `json:"remark"` +} + +// generalOutboundHandler 通用出库(手动出库,不依赖工单) +// 适用:退料 / 样品 / 报废 / 发货 等不挂靠 MES 工单的场景。 +// 支持结构件批次与精密件 SN;填箱号时一并把装箱信息(箱号/SN清单/合同号) +// 落到统一的出库主表,不再另建装箱表。 +// 事务保证:出库单 + 库存扣减 + 出库明细 原子提交;库存用条件原子更新避免负库存。 +func generalOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req generalOutboundRequest + if err := parseJSON(r, &req); err != nil { + fail(w, http.StatusBadRequest, "参数错误: "+err.Error()) + return + } + if req.MaterialCode == "" { + fail(w, http.StatusBadRequest, "materialCode 必填") + return + } + if req.BatchNo == "" && len(req.SnList) == 0 { + fail(w, http.StatusBadRequest, "batchNo 或 snList 至少提供一个") + return + } + + manageMode := 1 + if len(req.SnList) > 0 { + manageMode = 2 + } + // SN 出库数量以列表长度计 + actualQty := req.Qty + if manageMode == 2 { + actualQty = len(req.SnList) + } + if actualQty <= 0 { + fail(w, http.StatusBadRequest, "数量必须大于 0") + return + } + + outboundNo := "OB" + uuid.NewString()[:12] + + tx, err := ctx.EntClient.Tx(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, "开启事务失败: "+err.Error()) + return + } + committed := false + defer func() { + if !committed { + _ = tx.Rollback() + } + }() + + ob, err := tx.OutboundOrder.Create(). + SetOutboundNo(outboundNo). + SetOutboundType("general"). + SetMaterialCode(req.MaterialCode). + SetManageMode(manageMode). + SetNillableBatchNo(strPtr(req.BatchNo)). + SetNillableZoneCode(strPtr(req.ZoneCode)). + SetQuantity(0). + SetNillableOperator(strPtr(req.Operator)). + SetNillableRemark(strPtr(req.Remark)). + SetNillableBoxNo(strPtr(req.BoxNo)). + SetNillableContractNo(strPtr(req.ContractNo)). + Save(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, "创建出库单失败: "+err.Error()) + return + } + + // 批次扣减(结构件) + if req.BatchNo != "" { + b, err := tx.Inventory.Query(). + Where(inventory.ManageModeEQ(1), inventory.BatchNoEQ(req.BatchNo)). + Only(ctx0()) + if err != nil { + fail(w, http.StatusBadRequest, "批次不存在: "+req.BatchNo) + return + } + avail := b.Quantity - b.LockedQty + if avail < actualQty { + fail(w, http.StatusConflict, "批次库存不足: "+req.BatchNo+" 可用 "+itoa(avail)) + return + } + aff, err := tx.Inventory.Update(). + Where(inventory.ID(b.ID), inventory.QuantityGTE(actualQty)). + AddQuantity(-actualQty). + AddLockedQty(-min(actualQty, b.LockedQty)). + Save(ctx0()) + if err != nil || aff == 0 { + fail(w, http.StatusConflict, "批次扣减失败(库存不足或并发冲突): "+req.BatchNo) + return + } + if _, err = tx.OutboundDetail.Create(). + SetOutboundNo(outboundNo). + SetBatchNo(req.BatchNo). + SetMaterialCode(req.MaterialCode). + SetQuantity(actualQty). + Save(ctx0()); err != nil { + fail(w, http.StatusInternalServerError, "创建出库明细失败: "+err.Error()) + return + } + } + + // SN 扣减(精密件):仅在库/锁定的 SN 可出库 + if len(req.SnList) > 0 { + for _, sn := range req.SnList { + aff, err := tx.Inventory.Update(). + Where(inventory.ManageModeEQ(2), inventory.SnCodeEQ(sn), inventory.StatusIn("在库", "锁定")). + SetStatus("出库"). + SetNillableZoneCode(strPtr(req.ZoneCode)). + Save(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, "SN 出库失败: "+sn+" "+err.Error()) + return + } + if aff == 0 { + fail(w, http.StatusBadRequest, "SN 不可出库(不存在或非在库/锁定): "+sn) + return + } + if _, err = tx.OutboundDetail.Create(). + SetOutboundNo(outboundNo). + SetSnCode(sn). + SetMaterialCode(req.MaterialCode). + SetQuantity(1). + Save(ctx0()); err != nil { + fail(w, http.StatusInternalServerError, "创建出库明细失败: "+err.Error()) + return + } + } + } + + // 回写实际数量 + 装箱 SN 清单(JSON) + upd := tx.OutboundOrder.UpdateOneID(ob.ID).SetQuantity(actualQty) + if len(req.SnList) > 0 && req.BoxNo != "" { + upd.SetBoxSnList(snListJSON(req.SnList)) + } + if _, err = upd.Save(ctx0()); err != nil { + fail(w, http.StatusInternalServerError, "更新出库单失败: "+err.Error()) + return + } + + if err = tx.Commit(); err != nil { + fail(w, http.StatusInternalServerError, "提交事务失败: "+err.Error()) + return + } + committed = true + + logx.Infof("general outbound: material=%s qty=%d box=%s", req.MaterialCode, actualQty, req.BoxNo) + ok(w, map[string]any{ + "outboundNo": outboundNo, + "qty": actualQty, + "boxNo": req.BoxNo, + "type": "general", + }) + } +} + +// snListJSON 把 SN 列表序列化为 JSON 数组字符串 +func snListJSON(sn []string) string { + b, err := json.Marshal(sn) + if err != nil { + return "[]" + } + return string(b) +} + +// exportOutboundHandler 统一主表全部出库记录导出 +// 不依赖前端分页,一次返回全部(可按类型/工单/物料/箱号过滤),便于整表导出。 +func exportOutboundHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + outboundType := r.URL.Query().Get("outboundType") + orderNo := r.URL.Query().Get("orderNo") + materialCode := r.URL.Query().Get("materialCode") + boxNo := r.URL.Query().Get("boxNo") + + q := ctx.EntClient.OutboundOrder.Query() + if outboundType != "" { + q = q.Where(outboundorder.OutboundTypeEQ(outboundType)) + } + if orderNo != "" { + q = q.Where(outboundorder.OrderNoEQ(orderNo)) + } + if materialCode != "" { + q = q.Where(outboundorder.MaterialCodeEQ(materialCode)) + } + if boxNo != "" { + q = q.Where(outboundorder.BoxNoContains(boxNo)) + } + + list, err := q.Order(ent.Desc("created_at")).All(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + + type exportRow struct { + *ent.OutboundOrder + SnCodes string `json:"snCodes"` + Details []*ent.OutboundDetail `json:"details"` + } + rows := make([]exportRow, 0, len(list)) + for _, ob := range list { + details, _ := ctx.EntClient.OutboundDetail.Query(). + Where(outbounddetail.OutboundNoEQ(ob.OutboundNo)). + All(ctx0()) + er := exportRow{OutboundOrder: ob, SnCodes: "", Details: details} + sns := make([]string, 0, len(details)) + for _, d := range details { + if d.SnCode != "" { + sns = append(sns, d.SnCode) + } + } + if len(sns) > 0 { + er.SnCodes = strings.Join(sns, ",") + } + rows = append(rows, er) + } + + // xlsx 导出 + if r.URL.Query().Get("format") == "xlsx" { + headers := []string{"出库单号", "类型", "工单号", "物料编码", "物料名称", "数量", "装箱号", "合同号", "SN清单", "创建时间"} + matrix := make([][]any, 0, len(rows)) + for _, row := range rows { + ob := row.OutboundOrder + tn := "通用出库" + if ob.OutboundType == "workorder" { + tn = "备料出库" + } + matrix = append(matrix, []any{ + ob.OutboundNo, tn, ob.OrderNo, ob.MaterialCode, ob.MaterialName, + ob.Quantity, ob.BoxNo, ob.ContractNo, row.SnCodes, + unixFmt(ob.CreatedAt), + }) + } + sendExcel(w, xlsxFilename("出库管理"), headers, matrix) + return + } + + ok(w, map[string]any{"total": len(rows), "list": rows}) + } +} + func min(a, b int) int { if a < b { return a diff --git a/bj_power_wms/internal/handler/rbac.go b/bj_power_wms/internal/handler/rbac.go index ee37b70..abb38ae 100644 --- a/bj_power_wms/internal/handler/rbac.go +++ b/bj_power_wms/internal/handler/rbac.go @@ -6,6 +6,7 @@ import ( "strings" "bj_power_wms/ent" + userrole "bj_power_wms/ent/role" "bj_power_wms/ent/user" "bj_power_wms/internal/svc" @@ -15,31 +16,32 @@ import ( // 密码最小长度(注册 / 改密 / 重置统一) const minPasswordLen = 6 -// rolePermissions 角色 → 菜单/功能权限码。 -// 与前端 MainLayout 的菜单 code 一一对应;admin 拥有全部权限(含 user:manage)。 -var rolePermissions = map[string][]string{ - "admin": { - "dashboard:view", "inbound:view", "outbound:view", "inventory:view", - "inspection:view", "stocktake:view", "semi:view", "package:view", - "ledger:view", "zone:view", "material:view", "user:manage", - }, - "operator": { - "dashboard:view", "inbound:view", "outbound:view", "inventory:view", - "stocktake:view", "semi:view", "package:view", - "ledger:view", "zone:view", "material:view", - }, - "inspector": { - "dashboard:view", "inspection:view", "inventory:view", - "stocktake:view", "ledger:view", "zone:view", "material:view", - }, +// legacyRolePermissions 旧的角色 → 权限码映射(已废弃)。 +// 保留此常量的价值:作为「用户 role_id 为空」时的语义兜底,但此兜底直接查 roles 表 +// (按 role 字符串匹配 code),不再依赖这段硬编码数组。本常量仅作注释参照,不再被逻辑引用。 + +// permissionsForRole 按角色字符串 from roles 表取权限码(数据兜底,非硬编码)。 +// 用于 admin/operator/inspector 这类内置角色名,即使某用户未绑定 role_id 也能从数据库取到权限。 +func permissionsForRole(ctx *svc.ServiceContext, role string) []string { + rl, err := ctx.EntClient.Role.Query().Where(userrole.CodeEQ(role)).Only(ctx0()) + if err != nil || len(rl.PermissionCodes) == 0 { + return []string{} + } + return rl.PermissionCodes } -// permissionsForRole 取角色对应的权限码列表(未知角色按 operator 处理) -func permissionsForRole(role string) []string { - if p, ok := rolePermissions[role]; ok { - return p +// permissionsForUser 取用户权限码: +// 1. 有 role_id → 直接读该角色的 permission_codes +// 2. 无 role_id(历史账号) → 按 role 字符串从 roles 表查内置角色兜底 +// 纯数据来源,不含任何硬编码权限映射。 +func permissionsForUser(ctx *svc.ServiceContext, u *ent.User) []string { + if u.RoleID > 0 { + rl, err := ctx.EntClient.Role.Get(ctx0(), u.RoleID) + if err == nil && len(rl.PermissionCodes) > 0 { + return rl.PermissionCodes + } } - return rolePermissions["operator"] + return permissionsForRole(ctx, u.Role) } // roleOrDefault 规范化角色值,非法值回退 operator @@ -88,9 +90,10 @@ func userInfoHandler(ctx *svc.ServiceContext) http.HandlerFunc { "username": u.Username, "realName": u.RealName, "role": u.Role, + "roleId": u.RoleID, "dept": u.Dept, "isActive": u.IsActive, - "permissionCodes": permissionsForRole(u.Role), + "permissionCodes": permissionsForUser(ctx, u), }) } } @@ -102,6 +105,7 @@ func userDTO(u *ent.User) map[string]any { "username": u.Username, "realName": u.RealName, "role": u.Role, + "roleId": u.RoleID, "dept": u.Dept, "phone": u.Phone, "isActive": u.IsActive, @@ -134,6 +138,7 @@ func createUserHandler(ctx *svc.ServiceContext) http.HandlerFunc { Password string `json:"password"` RealName string `json:"realName"` Role string `json:"role"` + RoleID int `json:"roleId"` Dept string `json:"dept"` } if err := parseJSON(r, &req); err != nil { @@ -159,11 +164,20 @@ func createUserHandler(ctx *svc.ServiceContext) http.HandlerFunc { return } role := roleOrDefault(req.Role) + // role 字符串与 role_id 用同一角色语义:优先 role_id(数据化),否则按字符串回退。 + // 若用户给的是 role_code,尝试从 roles 表反查 role_id。 + roleID := req.RoleID + if roleID == 0 { + if rl, err := ctx.EntClient.Role.Query().Where(userrole.CodeEQ(role)).Only(ctx0()); err == nil { + roleID = rl.ID + } + } u, err := ctx.EntClient.User.Create(). SetUsername(req.Username). SetPassword(string(hash)). SetNillableRealName(strPtr(req.RealName)). SetRole(role). + SetRoleID(roleID). SetNillableDept(strPtr(req.Dept)). Save(ctx0()) if err != nil { @@ -181,6 +195,7 @@ func updateUserHandler(ctx *svc.ServiceContext) http.HandlerFunc { ID int `json:"id"` RealName string `json:"realName"` Role string `json:"role"` + RoleID int `json:"roleId"` Dept string `json:"dept"` IsActive *bool `json:"isActive"` Password string `json:"password"` @@ -201,6 +216,9 @@ func updateUserHandler(ctx *svc.ServiceContext) http.HandlerFunc { if req.Role != "" { upd.SetRole(roleOrDefault(req.Role)) } + if req.RoleID > 0 { + upd.SetRoleID(req.RoleID) + } if req.Dept != "" { upd.SetNillableDept(strPtr(req.Dept)) } diff --git a/bj_power_wms/internal/handler/rbac_admin.go b/bj_power_wms/internal/handler/rbac_admin.go new file mode 100644 index 0000000..98b62da --- /dev/null +++ b/bj_power_wms/internal/handler/rbac_admin.go @@ -0,0 +1,259 @@ +package handler + +import ( + "net/http" + + "bj_power_wms/ent" + "bj_power_wms/ent/permission" + "bj_power_wms/ent/role" + "bj_power_wms/ent/user" + "bj_power_wms/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +// 种子权限定义:MENU=菜单权限(对应侧栏,path 为路由);BUTTON=按钮级权限(页面内操作) +type seedPerm struct { + Code string + Name string + Type string + Path string + Icon string + Sort int +} + +var seedPermissions = []seedPerm{ + // ===== 菜单权限 ===== + {"dashboard:view", "工作台", "MENU", "/", "HomeFilled", 10}, + {"inbound:view", "入库管理", "MENU", "/inbound", "Download", 20}, + {"outbound:view", "出库管理", "MENU", "/outbound", "Upload", 30}, + {"inventory:view", "库存查询", "MENU", "/inventory", "Search", 40}, + {"inspection:view", "质量检验", "MENU", "/inspection", "CircleCheck", 50}, + {"stocktake:view", "库存盘点", "MENU", "/stocktake", "List", 60}, + {"semi:view", "半成品/成品", "MENU", "/semi", "Box", 70}, + {"ledger:view", "备料台账", "MENU", "/ledger", "Tickets", 80}, + {"zone:view", "区域维护", "MENU", "/zone", "Location", 90}, + {"material:view", "物料档案", "MENU", "/material", "Goods", 100}, + {"user:manage", "账号管理", "MENU", "/users", "EditPen", 110}, + {"role:manage", "角色管理", "MENU", "/roles", "Key", 120}, + // ===== 按钮权限 ===== + {"inbound:create", "批量入库", "BUTTON", "", "", 200}, + {"inbound:import", "Excel导入", "BUTTON", "", "", 201}, + {"outbound:create", "发起出库", "BUTTON", "", "", 210}, + {"inspection:create", "录入检验", "BUTTON", "", "", 220}, + {"stocktake:start", "发起盘点", "BUTTON", "", "", 230}, + {"stocktake:writeback", "差异写回", "BUTTON", "", "", 231}, + {"material:create", "新增物料", "BUTTON", "", "", 240}, + {"material:edit", "编辑物料", "BUTTON", "", "", 241}, + {"material:delete", "删除物料", "BUTTON", "", "", 242}, + {"zone:create", "新增区域", "BUTTON", "", "", 250}, + {"zone:edit", "编辑区域", "BUTTON", "", "", 251}, + {"zone:delete", "删除区域", "BUTTON", "", "", 252}, + {"user:create", "新增账号", "BUTTON", "", "", 260}, + {"user:edit", "编辑账号", "BUTTON", "", "", 261}, + {"user:delete", "删除账号", "BUTTON", "", "", 262}, + {"role:create", "新增角色", "BUTTON", "", "", 270}, + {"role:edit", "编辑角色", "BUTTON", "", "", 271}, + {"role:delete", "删除角色", "BUTTON", "", "", 272}, + {"*:export", "导出", "BUTTON", "", "", 280}, +} + +// 三角色预置权限(对齐原硬编码 rolePermissions,并补充按钮权限) +// admin 全量;operator 除账号/角色管理外全部;inspector 仅质检相关 +func seedRoleCodes() map[string][]string { + all := make([]string, 0, len(seedPermissions)) + for _, p := range seedPermissions { + all = append(all, p.Code) + } + oper := make([]string, 0, len(seedPermissions)) + for _, p := range seedPermissions { + if p.Code == "user:manage" || p.Code == "role:manage" || + p.Code == "user:create" || p.Code == "user:edit" || p.Code == "user:delete" || + p.Code == "role:create" || p.Code == "role:edit" || p.Code == "role:delete" { + continue + } + oper = append(oper, p.Code) + } + insp := []string{ + "dashboard:view", "inventory:view", "inspection:view", "inspection:create", + "stocktake:view", "ledger:view", "zone:view", "material:view", "*:export", + } + return map[string][]string{"admin": all, "operator": oper, "inspector": insp} +} + +var seedRoleMeta = []struct { + Code string + Name string + Remark string +}{ + {"admin", "管理员", "系统管理员,拥有全部权限"}, + {"operator", "库房保管员", "入库/出库/库存/盘点等日常作业"}, + {"inspector", "质检员", "质量检验相关"}, +} + +// seedRbacHandler POST /api/rbac/seed 幂等初始化权限与角色(已存在按 code 跳过) +func seedRbacHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return requireAdmin(func(w http.ResponseWriter, r *http.Request) { + createdP, createdR := 0, 0 + for _, p := range seedPermissions { + exist, _ := ctx.EntClient.Permission.Query(). + Where(permission.CodeEQ(p.Code)).Exist(ctx0()) + if exist { + continue + } + _, err := ctx.EntClient.Permission.Create(). + SetCode(p.Code).SetName(p.Name).SetType(p.Type). + SetPath(p.Path).SetIcon(p.Icon).SetSort(p.Sort). + Save(ctx0()) + if err == nil { + createdP++ + } + } + codes := seedRoleCodes() + bound := 0 + for _, m := range seedRoleMeta { + rl, err := ctx.EntClient.Role.Query(). + Where(role.CodeEQ(m.Code)).Only(ctx0()) + if err != nil { + // 内置角色不存在则创建 + rl, err = ctx.EntClient.Role.Create(). + SetCode(m.Code).SetName(m.Name).SetRemark(m.Remark). + SetPermissionCodes(codes[m.Code]). + Save(ctx0()) + if err != nil { + continue + } + createdR++ + } + // 把「role 字符串 == 该角色 code」的历史用户绑定到 role_id(幂等,仅绑定 role_id 为空者) + users, _ := ctx.EntClient.User.Query(). + Where(user.RoleEQ(m.Code), user.RoleIDIsNil()).All(ctx0()) + for _, u := range users { + if _, err := ctx.EntClient.User.UpdateOneID(u.ID).SetRoleID(rl.ID).Save(ctx0()); err == nil { + bound++ + } + } + } + logx.Infof("rbac seed: 新增权限 %d 条、角色 %d 个、绑定历史用户 %d 个", createdP, createdR, bound) + ok(w, map[string]any{"createdPermissions": createdP, "createdRoles": createdR, "boundUsers": bound}) + }) +} + +// listRolesHandler GET /api/roles 角色列表(含权限码) +func listRolesHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + list, err := ctx.EntClient.Role.Query().Order(ent.Asc("id")).All(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + ok(w, map[string]any{"list": list}) + } +} + +// createRoleHandler POST /api/roles 新增角色 +func createRoleHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return requireAdmin(func(w http.ResponseWriter, r *http.Request) { + var req struct { + Name string `json:"name"` + Code string `json:"code"` + Remark string `json:"remark"` + PermissionCodes []string `json:"permissionCodes"` + } + if err := parseJSON(r, &req); err != nil || req.Code == "" || req.Name == "" { + fail(w, http.StatusBadRequest, "角色名称与编码必填") + return + } + exist, _ := ctx.EntClient.Role.Query().Where(role.CodeEQ(req.Code)).Exist(ctx0()) + if exist { + fail(w, http.StatusConflict, "角色编码已存在: "+req.Code) + return + } + codes := req.PermissionCodes + if codes == nil { + codes = []string{} + } + rl, err := ctx.EntClient.Role.Create(). + SetName(req.Name).SetCode(req.Code). + SetNillableRemark(strPtr(req.Remark)). + SetPermissionCodes(codes).Save(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + ok(w, rl) + }) +} + +// updateRoleHandler POST /api/roles/update 编辑角色(含权限勾选) +func updateRoleHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return requireAdmin(func(w http.ResponseWriter, r *http.Request) { + var req struct { + ID int `json:"id"` + Name string `json:"name"` + Remark string `json:"remark"` + PermissionCodes []string `json:"permissionCodes"` + } + if err := parseJSON(r, &req); err != nil || req.ID <= 0 { + fail(w, http.StatusBadRequest, "参数错误") + return + } + // 角色编码创建后不可修改(前端亦置灰),此处只改名称/备注/权限 + upd := ctx.EntClient.Role.UpdateOneID(req.ID) + if req.Name != "" { + upd = upd.SetName(req.Name) + } + if req.Remark != "" { + upd = upd.SetRemark(req.Remark) + } + if req.PermissionCodes != nil { + upd = upd.SetPermissionCodes(req.PermissionCodes) + } + rl, err := upd.Save(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + ok(w, rl) + }) +} + +// deleteRoleHandler POST /api/roles/delete 删除角色(内置三角色禁止删除) +func deleteRoleHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return requireAdmin(func(w http.ResponseWriter, r *http.Request) { + var req struct { + ID int `json:"id"` + } + if err := parseJSON(r, &req); err != nil || req.ID <= 0 { + fail(w, http.StatusBadRequest, "参数错误") + return + } + target, err := ctx.EntClient.Role.Get(ctx0(), req.ID) + if err != nil { + fail(w, http.StatusNotFound, "角色不存在") + return + } + if target.Code == "admin" || target.Code == "operator" || target.Code == "inspector" { + fail(w, http.StatusBadRequest, "内置角色不可删除: "+target.Code) + return + } + if err := ctx.EntClient.Role.DeleteOneID(req.ID).Exec(ctx0()); err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + ok(w, nil) + }) +} + +// listPermissionsHandler GET /api/permissions 权限列表(菜单+按钮,按 sort 排序) +func listPermissionsHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + list, err := ctx.EntClient.Permission.Query(). + Order(ent.Asc("sort"), ent.Asc("id")).All(ctx0()) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + ok(w, map[string]any{"list": list}) + } +} diff --git a/bj_power_wms/internal/handler/routes.go b/bj_power_wms/internal/handler/routes.go index 5cd24b0..5bbe3b5 100644 --- a/bj_power_wms/internal/handler/routes.go +++ b/bj_power_wms/internal/handler/routes.go @@ -30,6 +30,18 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) { }, ) + // 角色与权限(RBAC 数据化,取代 rbac.go 中的硬编码权限 map) + server.AddRoutes( + []rest.Route{ + {Method: http.MethodPost, Path: "/api/rbac/seed", Handler: seedRbacHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/roles", Handler: listRolesHandler(ctx)}, + {Method: http.MethodPost, Path: "/api/roles", Handler: createRoleHandler(ctx)}, + {Method: http.MethodPost, Path: "/api/roles/update", Handler: updateRoleHandler(ctx)}, + {Method: http.MethodPost, Path: "/api/roles/delete", Handler: deleteRoleHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/permissions", Handler: listPermissionsHandler(ctx)}, + }, + ) + // 物料档案 server.AddRoutes( []rest.Route{ @@ -41,20 +53,24 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) { }, ) - // 入库 - server.AddRoutes( - []rest.Route{ - {Method: http.MethodPost, Path: "/api/inbound/create", Handler: createInboundHandler(ctx)}, + // 入库 + server.AddRoutes( + []rest.Route{ + {Method: http.MethodPost, Path: "/api/inbound/create", Handler: createInboundHandler(ctx)}, {Method: http.MethodGet, Path: "/api/inbound/query", Handler: queryInboundHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/inbound/details", Handler: inboundDetailsHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/inbound/export", Handler: exportInboundHandler(ctx)}, {Method: http.MethodPost, Path: "/api/inbound/batch-excel", Handler: excelInboundHandler(ctx)}, - }, - ) + }, + ) - // 出库 + // 出库(统一主表:备料出库 workorder / 通用出库 general,装箱信息落在同一张表) server.AddRoutes( []rest.Route{ {Method: http.MethodPost, Path: "/api/outbound/create", Handler: createOutboundHandler(ctx)}, + {Method: http.MethodPost, Path: "/api/outbound/general", Handler: generalOutboundHandler(ctx)}, {Method: http.MethodGet, Path: "/api/outbound/query", Handler: queryOutboundHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/outbound/export", Handler: exportOutboundHandler(ctx)}, }, ) @@ -62,6 +78,8 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ {Method: http.MethodGet, Path: "/api/stock/query", Handler: queryStockHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/stock/details", Handler: stockDetailsHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/stock/export", Handler: exportStockHandler(ctx)}, {Method: http.MethodGet, Path: "/api/stock/zone-summary", Handler: zoneSummaryHandler(ctx)}, {Method: http.MethodPost, Path: "/api/stock/lock", Handler: lockStockHandler(ctx)}, {Method: http.MethodPost, Path: "/api/stock/unlock", Handler: unlockStockHandler(ctx)}, @@ -76,6 +94,7 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) { {Method: http.MethodPost, Path: "/api/inspection/create", Handler: createInspectionHandler(ctx)}, {Method: http.MethodPost, Path: "/api/inspection/batch-flip", Handler: batchFlipInspectionHandler(ctx)}, {Method: http.MethodGet, Path: "/api/inspection/query", Handler: queryInspectionHandler(ctx)}, + {Method: http.MethodGet, Path: "/api/inspection/export", Handler: exportInspectionHandler(ctx)}, }, ) @@ -108,15 +127,6 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) { }, ) - // 包装 - server.AddRoutes( - []rest.Route{ - {Method: http.MethodPost, Path: "/api/package/bind", Handler: packageBindHandler(ctx)}, - {Method: http.MethodPost, Path: "/api/package/update", Handler: packageUpdateHandler(ctx)}, - {Method: http.MethodGet, Path: "/api/package/query", Handler: queryPackageHandler(ctx)}, - }, - ) - // 工单物料台账(WMS 侧) server.AddRoutes( []rest.Route{ diff --git a/bj_power_wms/internal/handler/stock.go b/bj_power_wms/internal/handler/stock.go index e5cc902..076c315 100644 --- a/bj_power_wms/internal/handler/stock.go +++ b/bj_power_wms/internal/handler/stock.go @@ -4,31 +4,273 @@ import ( "fmt" "net/http" "strings" + "time" "entgo.io/ent/dialect/sql" "bj_power_wms/ent" "bj_power_wms/ent/inventory" "bj_power_wms/ent/inventorylock" + "bj_power_wms/ent/material" "bj_power_wms/ent/predicate" "bj_power_wms/internal/svc" ) -// queryStockHandler 库存查询(MES 查料 / 客户端查料) -// 统一查询 inventory 一张表:按 物料编码/区域/关键字/管理粒度(manageMode) 过滤。 -// 返回单一 list(结构件与精密件同表),前端统一展示、统一导出。 +// stockKey 库存聚合行的唯一标识(组合键)+ 明细下钻的过滤条件 +type stockKey struct { + MaterialCode string + ZoneCode string + QualityStatus string + ManageMode int +} + +// stockAggRow 聚合主列表的行结构(按 物料+区域+质量+管理粒度 聚合,只返回数量,不铺开明细) +type stockAggRow struct { + ID int64 `json:"id"` // 组合键稳定序号的伪 id,供前端行 key 使用 + MaterialCode string `json:"materialCode"` // 物料编码 + MaterialName string `json:"materialName"` // 物料名称 + Spec string `json:"spec"` // 规格型号 + ManageMode int `json:"manageMode"` // 1结构件/2精密件 + ZoneCode string `json:"zoneCode"` // 区域 + QualityStatus string `json:"qualityStatus"` // 质量状态 + TotalQty int `json:"totalQty"` // 总数量(结构件=数量求和;精密件=SN 行数) + LockedQty int `json:"lockedQty"` // 锁定量 + AvailQty int `json:"availQty"` // 可用量 = total - locked + BatchCount int `json:"batchCount"` // 批次数量(结构件维度的行数) + SnCount int `json:"snCount"` // SN 数量(精密件维度的行数) + LastInboundNo string `json:"lastInboundNo"` // 最近入库单号 + CreatedAt int64 `json:"createdAt"` // 最近一次入库时间(聚合组内最大 created_at) +} + +// queryStockHandler 库存查询(主列表 = 按物料聚合数量) +// 统一查询 inventory 一张表,按 物料编码+区域+质量状态+管理粒度 分组聚合, +// 只返回每个物料的数量/锁定/可用与 批次数/SN数,不把每个批次/SN 平铺出来(避免 SN 泄漏与数据量膨胀)。 +// 明细通过 /api/stock/details 点击下钻(分页懒加载)。 func queryStockHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { materialCode := r.URL.Query().Get("materialCode") + materialName := r.URL.Query().Get("materialName") // 物料名称模糊 zoneCode := r.URL.Query().Get("zoneCode") + qualityStatus := r.URL.Query().Get("qualityStatus") manageMode := r.URL.Query().Get("manageMode") // 1/2/空=全部 - keyword := r.URL.Query().Get("keyword") + inboundNo := r.URL.Query().Get("inboundNo") + startDate := r.URL.Query().Get("startDate") // 默认近3个月(由接口保证) + endDate := r.URL.Query().Get("endDate") + page := atoi(r.URL.Query().Get("page"), 1) + pageSize := atoi(r.URL.Query().Get("pageSize"), 20) + + rows, total, err := aggregateStock(ctx, aggregateStockArgs{ + MaterialCode: materialCode, + MaterialName: materialName, + ZoneCode: zoneCode, + QualityStatus: qualityStatus, + ManageMode: manageMode, + InboundNo: inboundNo, + StartDate: startDate, + EndDate: endDate, + Page: page, + PageSize: pageSize, + }) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + ok(w, map[string]any{ + "list": rows, + "total": total, + "page": page, + "pageSize": pageSize, + }) + } +} + +// aggregateStockArgs 聚合主列表的筛选条件 +type aggregateStockArgs struct { + MaterialCode string + MaterialName string + ZoneCode string + QualityStatus string + ManageMode string + InboundNo string + StartDate string + EndDate string + Page int + PageSize int +} + +// aggregateStock 按物料聚合库存主数据。 +// 用相机内存聚合(inventory 表每物料的行数有限:结构件=批次数、精密件=SN 数), +// 先拉取符合状态条件的行,在 Go 侧分组聚合,再做内存分页。 +// 这样避免手写 GROUP BY 子查询的复杂度,且数据量受"在库/锁定"上限约束,安全可控。 +func aggregateStock(ctx *svc.ServiceContext, a aggregateStockArgs) ([]*stockAggRow, int, error) { + q := ctx.EntClient.Inventory.Query() + // 仅展示在库/锁定(出库/使用/报废不计入库存) + q = q.Where(inventory.StatusIn("在库", "锁定")) + // 结构件隐藏数量为 0 的行 + q = q.Where(inventory.Or(inventory.ManageModeEQ(2), inventory.QuantityGT(0))) + + if a.MaterialCode != "" { + q = q.Where(inventory.MaterialCodeContains(a.MaterialCode)) + } + if a.MaterialName != "" { + q = q.Where(inventory.MaterialNameContains(a.MaterialName)) + } + if a.ZoneCode != "" { + q = q.Where(inventory.ZoneCodeEQ(a.ZoneCode)) + } + if a.QualityStatus != "" { + q = q.Where(inventory.QualityStatusEQ(a.QualityStatus)) + } + if a.InboundNo != "" { + q = q.Where(inventory.InboundNoContains(a.InboundNo)) + } + if a.ManageMode == "1" { + q = q.Where(inventory.ManageModeEQ(1)) + } else if a.ManageMode == "2" { + q = q.Where(inventory.ManageModeEQ(2)) + } + // 时间筛选:默认近3个月 + startUnix := int64(0) + if a.StartDate != "" { + if t, err := time.ParseInLocation("2006-01-02", a.StartDate, time.Local); err == nil { + startUnix = t.Unix() + } + } + endUnix := int64(0) + if a.EndDate != "" { + if t, err := time.ParseInLocation("2006-01-02", a.EndDate, time.Local); err == nil { + endUnix = t.Add(24 * time.Hour).Unix() // 含当天全天 + } + } + if a.StartDate == "" && a.EndDate == "" { + startUnix = time.Now().AddDate(0, -3, 0).Unix() // 默认近3个月 + } + if startUnix > 0 { + q = q.Where(inventory.CreatedAtGTE(startUnix)) + } + if endUnix > 0 { + q = q.Where(inventory.CreatedAtLTE(endUnix)) + } + + all, err := q.Order(ent.Desc("created_at")).All(ctx0()) + if err != nil { + return nil, 0, err + } + + // 收集物料信息(名称/规格从 materials 表补齐,字段更权威) + matName := map[string]string{} + matSpec := map[string]string{} + matCodes := []string{} + seen := map[string]bool{} + for _, inv := range all { + if !seen[inv.MaterialCode] { + seen[inv.MaterialCode] = true + matCodes = append(matCodes, inv.MaterialCode) + } + } + if len(matCodes) > 0 { + mats, _ := ctx.EntClient.Material.Query(). + Where(material.CodeIn(matCodes...)).All(ctx0()) + for _, m := range mats { + matName[m.Code] = m.Name + matSpec[m.Code] = m.Spec + } + } + + // 分组聚合 + type agg struct { + totalQty int + lockedQty int + batchCnt int + snCnt int + lastInbNo string + lastTime int64 + } + group := map[stockKey]*agg{} + order := []stockKey{} + for _, inv := range all { + zc := inv.ZoneCode + if zc == "" { + zc = "未分区" + } + key := stockKey{inv.MaterialCode, zc, inv.QualityStatus, inv.ManageMode} + g, ok := group[key] + if !ok { + g = &agg{} + group[key] = g + order = append(order, key) + } + if inv.ManageMode == 1 { + g.totalQty += inv.Quantity + g.lockedQty += inv.LockedQty + g.batchCnt++ + } else { + g.totalQty++ + if inv.Status == "锁定" { + g.lockedQty++ + } + g.snCnt++ + } + if inv.CreatedAt > g.lastTime { + g.lastTime = inv.CreatedAt + g.lastInbNo = inv.InboundNo + } + } + + total := len(order) + // 分页 + start := (a.Page - 1) * a.PageSize + if start < 0 { + start = 0 + } + end := start + a.PageSize + if end > total { + end = total + } + rows := make([]*stockAggRow, 0, end-start) + for i := start; i < end; i++ { + key := order[i] + g := group[key] + name := matName[key.MaterialCode] + if name == "" { + name = key.MaterialCode + } + rows = append(rows, &stockAggRow{ + ID: int64(i + 1), + MaterialCode: key.MaterialCode, + MaterialName: name, + Spec: matSpec[key.MaterialCode], + ManageMode: key.ManageMode, + ZoneCode: key.ZoneCode, + QualityStatus: key.QualityStatus, + TotalQty: g.totalQty, + LockedQty: g.lockedQty, + AvailQty: g.totalQty - g.lockedQty, + BatchCount: g.batchCnt, + SnCount: g.snCnt, + LastInboundNo: g.lastInbNo, + CreatedAt: g.lastTime, + }) + } + return rows, total, nil +} + +// stockDetailsHandler 库存明细(点击聚合行下钻,分页懒加载) +// GET /api/stock/details?materialCode=&zoneCode=&qualityStatus=&manageMode=&page=&pageSize= +// 返回该物料/区域/质量/类型下的原始批次/SN 明细行(扁平展示,含 SN/批次号)。 +func stockDetailsHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + materialCode := r.URL.Query().Get("materialCode") + zoneCode := r.URL.Query().Get("zoneCode") + if zoneCode == "未分区" { + zoneCode = "" + } + qualityStatus := r.URL.Query().Get("qualityStatus") + manageMode := atoi(r.URL.Query().Get("manageMode"), 0) page := atoi(r.URL.Query().Get("page"), 1) pageSize := atoi(r.URL.Query().Get("pageSize"), 50) q := ctx.EntClient.Inventory.Query() - // 仅展示在库/锁定(出库/使用/报废不计入库存) q = q.Where(inventory.StatusIn("在库", "锁定")) - // 结构件隐藏数量为 0 的行 q = q.Where(inventory.Or(inventory.ManageModeEQ(2), inventory.QuantityGT(0))) if materialCode != "" { q = q.Where(inventory.MaterialCodeEQ(materialCode)) @@ -36,25 +278,19 @@ func queryStockHandler(ctx *svc.ServiceContext) http.HandlerFunc { if zoneCode != "" { q = q.Where(inventory.ZoneCodeEQ(zoneCode)) } - if manageMode == "1" { - q = q.Where(inventory.ManageModeEQ(1)) - } else if manageMode == "2" { - q = q.Where(inventory.ManageModeEQ(2)) + if qualityStatus != "" { + q = q.Where(inventory.QualityStatusEQ(qualityStatus)) } - if keyword != "" { - q = q.Where(inventory.Or( - inventory.BatchNoContains(keyword), - inventory.MaterialCodeContains(keyword), - inventory.SnCodeContains(keyword), - inventory.MaterialNameContains(keyword), - )) + if manageMode != 0 { + q = q.Where(inventory.ManageModeEQ(manageMode)) } + total, err := q.Count(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) @@ -69,6 +305,40 @@ func queryStockHandler(ctx *svc.ServiceContext) http.HandlerFunc { } } +// exportStockHandler 库存汇总全量导出(xlsx) +// 与 /stock/query 同一套聚合逻辑,但导出当前筛选下的全部行(不分页)。 +// 返回 .xlsx 二进制,文件名 = 库存汇总_时间.xlsx。 +func exportStockHandler(ctx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + rows, _, err := aggregateStock(ctx, aggregateStockArgs{ + MaterialCode: r.URL.Query().Get("materialCode"), + MaterialName: r.URL.Query().Get("materialName"), + ZoneCode: r.URL.Query().Get("zoneCode"), + QualityStatus: r.URL.Query().Get("qualityStatus"), + ManageMode: r.URL.Query().Get("manageMode"), + InboundNo: r.URL.Query().Get("inboundNo"), + StartDate: r.URL.Query().Get("startDate"), + EndDate: r.URL.Query().Get("endDate"), + Page: 1, + PageSize: 1000000, // 全量 + }) + if err != nil { + fail(w, http.StatusInternalServerError, err.Error()) + return + } + headers := []string{"物料编码", "物料名称", "规格", "类型", "区域", "质量状态", "总数量", "锁定量", "可用量", "批次数", "SN数", "最近入库单", "最近入库时间"} + matrix := make([][]any, 0, len(rows)) + for _, rw := range rows { + matrix = append(matrix, []any{ + rw.MaterialCode, rw.MaterialName, rw.Spec, + manageModeLabel(rw.ManageMode), rw.ZoneCode, rw.QualityStatus, + rw.TotalQty, rw.LockedQty, rw.AvailQty, rw.BatchCount, rw.SnCount, + rw.LastInboundNo, unixFmt(rw.CreatedAt), + }) + } + sendExcel(w, xlsxFilename("库存汇总"), headers, matrix) + } +} // zoneSummaryHandler 区域库存汇总(按 区域 + 质量状态 + 类型 聚合) // GET /api/stock/zone-summary // 返回 rows: [{zoneCode, zoneName, quality, type(批次/精密件), qty}] diff --git a/bj_power_wms/internal/handler/stocktake.go b/bj_power_wms/internal/handler/stocktake.go index 8e9b3b6..8d696e1 100644 --- a/bj_power_wms/internal/handler/stocktake.go +++ b/bj_power_wms/internal/handler/stocktake.go @@ -18,8 +18,11 @@ import ( func startStocktakeHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req struct { - Operator string `json:"operator"` - Zones []string `json:"zones"` // 可选:限定盘点区域,空=全部 + Operator string `json:"operator"` + Zones []string `json:"zones"` // 可选:限定盘点区域,空=全部 + MaterialCodes []string `json:"materialCodes"` // 可选:限定盘点物料,空=全部 + ManageMode int `json:"manageMode"` // 可选:1结构件/2精密件,0=全部 + QualityStatus string `json:"qualityStatus"` // 可选:限定质量状态,空=全部 } if err := parseJSON(r, &req); err != nil { fail(w, http.StatusBadRequest, "参数错误: "+err.Error()) @@ -32,6 +35,15 @@ func startStocktakeHandler(ctx *svc.ServiceContext) http.HandlerFunc { if len(req.Zones) > 0 { q = q.Where(inventory.ZoneCodeIn(req.Zones...)) } + if len(req.MaterialCodes) > 0 { + q = q.Where(inventory.MaterialCodeIn(req.MaterialCodes...)) + } + if req.ManageMode != 0 { + q = q.Where(inventory.ManageModeEQ(req.ManageMode)) + } + if req.QualityStatus != "" { + q = q.Where(inventory.QualityStatusEQ(req.QualityStatus)) + } rows, err := q.All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) @@ -259,7 +271,7 @@ func queryStocktakeHandler(ctx *svc.ServiceContext) http.HandlerFunc { if no == "" { orders, _ := ctx.EntClient.StocktakeOrder.Query(). - Order(ent.Desc("id")).Limit(100).All(ctx0()) + Order(ent.Desc("created_at")).Limit(100).All(ctx0()) ok(w, map[string]any{"list": orders}) return } @@ -272,7 +284,7 @@ func queryStocktakeHandler(ctx *svc.ServiceContext) http.HandlerFunc { } list, err := ctx.EntClient.StocktakeItem.Query(). Where(stocktakeitem.StocktakeNoEQ(no)). - Order(ent.Desc("id")). + Order(ent.Desc("created_at")). Offset((page - 1) * pageSize).Limit(pageSize).All(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) diff --git a/bj_power_wms/internal/handler/zone.go b/bj_power_wms/internal/handler/zone.go index d41f013..a246c3e 100644 --- a/bj_power_wms/internal/handler/zone.go +++ b/bj_power_wms/internal/handler/zone.go @@ -2,6 +2,7 @@ package handler import ( "net/http" + "time" "bj_power_wms/ent" "bj_power_wms/ent/zone" @@ -87,9 +88,23 @@ func listZonesHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { page := atoi(r.URL.Query().Get("page"), 1) pageSize := atoi(r.URL.Query().Get("pageSize"), 20) - keyword := r.URL.Query().Get("keyword") + zoneCode := r.URL.Query().Get("zoneCode") + zoneName := r.URL.Query().Get("zoneName") + status := r.URL.Query().Get("status") + startDate := r.URL.Query().Get("startDate") + endDate := r.URL.Query().Get("endDate") + keyword := r.URL.Query().Get("keyword") // 兼容旧版,作为区域编码/名称兜底 q := ctx.EntClient.Zone.Query() + if zoneCode != "" { + q = q.Where(zone.ZoneCodeContains(zoneCode)) + } + if zoneName != "" { + q = q.Where(zone.ZoneNameContains(zoneName)) + } + if status != "" { + q = q.Where(zone.StatusEQ(status)) + } if keyword != "" { q = q.Where( zone.Or( @@ -98,12 +113,22 @@ func listZonesHandler(ctx *svc.ServiceContext) http.HandlerFunc { ), ) } + if startDate != "" { + if t, err := time.ParseInLocation("2006-01-02", startDate, time.Local); err == nil { + q = q.Where(zone.CreatedAtGTE(t.Unix())) + } + } + if endDate != "" { + if t, err := time.ParseInLocation("2006-01-02", endDate, time.Local); err == nil { + q = q.Where(zone.CreatedAtLTE(t.Add(24 * time.Hour).Unix())) + } + } total, err := q.Count(ctx0()) if err != nil { fail(w, http.StatusInternalServerError, err.Error()) return } - list, err := q.Order(ent.Desc("id")). + list, err := q.Order(ent.Desc("created_at")). Offset((page - 1) * pageSize). Limit(pageSize). All(ctx0()) diff --git a/bj_power_wms/schema/inspection_record.go b/bj_power_wms/schema/inspection_record.go index 56b5c73..2d705a0 100644 --- a/bj_power_wms/schema/inspection_record.go +++ b/bj_power_wms/schema/inspection_record.go @@ -22,6 +22,12 @@ func (InspectionRecord) Fields() []ent.Field { field.String("inspection_type").Default("incoming").Comment("来料检/过程检/成品检"), field.String("status").Default("未检").Comment("未检/合格/不合格"), field.String("result_value").Optional().Comment("实测值(部分检验项)"), + // 检验数量 / 合格数量(量化闭环:来料/过程/成品检的批次抽检量) + field.Int("inspect_qty").Default(0).Comment("检验数量(抽检件数)"), + field.Int("pass_qty").Default(0).Comment("合格数量(≤检验数量)"), + // 检测说明 / 不合格原因 + field.String("check_desc").Optional().Comment("检测说明(检验项目/方法)"), + field.String("fail_reason").Optional().Comment("不合格原因(不合格时必填)"), field.String("inspector").Optional().Comment("检验人"), field.String("remark").Optional().Comment("备注"), field.Int64("created_at").DefaultFunc(nowUnix), diff --git a/bj_power_wms/schema/outbound_order.go b/bj_power_wms/schema/outbound_order.go index d4fbc26..9cbe665 100644 --- a/bj_power_wms/schema/outbound_order.go +++ b/bj_power_wms/schema/outbound_order.go @@ -6,8 +6,10 @@ import ( "entgo.io/ent/schema/index" ) -// OutboundOrder 出库单 -// 出库强约束:累计出库 ≤ 工单 BOM 需求量(由 MES 校验),WMS 侧校验 order_no 对应台账 +// OutboundOrder 出库统一主表 +// 所有出库(备料出库 workorder / 通用出库 general / 装箱)都落在这一张表, +// 用 outbound_type 区分;装箱属性(箱号/SN清单/合同号)直接存本表,不再单独建装箱表。 +// 备料出库强约束:累计出库 ≤ 工单 BOM 需求量(由 MES 校验),WMS 侧校验 order_no 对应台账。 type OutboundOrder struct { ent.Schema } @@ -15,7 +17,7 @@ type OutboundOrder struct { func (OutboundOrder) Fields() []ent.Field { return []ent.Field{ field.String("outbound_no").Unique().Comment("出库单号"), - // 类型:workorder(工单领料) semi(半成品) finished(成品) scrap(报废) + // 类型:workorder(工单领料/MES) general(通用出库,不依赖工单) field.String("outbound_type").Default("workorder").Comment("出库类型"), field.String("order_no").Optional().Comment("关联工单号(工单为唯一挂靠载体)"), field.String("material_code").Comment("物料编码"), @@ -28,6 +30,10 @@ func (OutboundOrder) Fields() []ent.Field { field.String("reviewer").Optional().Comment("复核人"), field.String("target_dock").Optional().Comment("目标接驳台(AGV配送)"), field.String("remark").Optional().Comment("备注"), + // 装箱属性:出库时一并记录箱号/SN清单/合同号,统一落在出库主表,不再单独建装箱表 + field.String("box_no").Optional().Comment("箱号(装箱出库时填写,用于整箱发货追溯)"), + field.String("box_sn_list").Optional().Comment("装箱 SN 清单(JSON 数组字符串)"), + field.String("contract_no").Optional().Comment("合同号(装箱选填)"), field.Int64("created_at").DefaultFunc(nowUnix).Comment("创建时间"), } } @@ -37,5 +43,6 @@ func (OutboundOrder) Indexes() []ent.Index { index.Fields("order_no"), index.Fields("material_code"), index.Fields("outbound_type"), + index.Fields("box_no"), } } diff --git a/bj_power_wms/schema/package_box.go b/bj_power_wms/schema/package_box.go deleted file mode 100644 index 172ca14..0000000 --- a/bj_power_wms/schema/package_box.go +++ /dev/null @@ -1,38 +0,0 @@ -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/field" - "entgo.io/ent/schema/index" -) - -// PackageBox 包装箱 ↔ SN 关联(装箱管理) -// 将一个或多个精密件 SN 绑定到一个箱号,便于整箱出入库与追溯。 -// sn_list 以字符串存多个 SN(逗号分隔 / JSON),不强制外键关联 inventory, -// 因为装箱是业务封装动作,箱内 SN 仍各自在 inventory 表中独立流转。 -type PackageBox struct { - ent.Schema -} - -func (PackageBox) Fields() []ent.Field { - return []ent.Field{ - field.String("box_no").Unique().Comment("箱号"), - // 关联 SN 列表(逗号分隔)或 JSON - field.String("sn_list").Optional().Comment("箱内 SN 列表"), - field.String("material_code").Optional().Comment("物料编码"), - field.Int("quantity").Default(0).Comment("箱内数量"), - field.String("operator").Optional().Comment("包装人"), - field.String("contract_no").Optional().Comment("合同号(选填)"), - field.String("remark").Optional().Comment("备注"), - field.Int64("created_at").DefaultFunc(nowUnix), - field.Int64("updated_at").DefaultFunc(nowUnix).Optional().Comment("更新时间"), - } -} - -func (PackageBox) Indexes() []ent.Index { - return []ent.Index{ - index.Fields("material_code"), - index.Fields("contract_no"), - index.Fields("operator"), - } -} diff --git a/bj_power_wms/schema/permission.go b/bj_power_wms/schema/permission.go new file mode 100644 index 0000000..8165e30 --- /dev/null +++ b/bj_power_wms/schema/permission.go @@ -0,0 +1,40 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +// Permission 权限/菜单 +// 模型移植自 MES(schema/permission.go),按 WMS 约定调整字段命名与时间类型。 +// type 区分两类: +// - MENU 菜单权限:对应侧栏菜单项,path 为前端路由 +// - BUTTON 按钮权限:对应页面内的操作按钮,无 path +type Permission struct { + ent.Schema +} + +func (Permission) Annotations() []schema.Annotation { + return []schema.Annotation{entsql.Annotation{Table: "permissions"}} +} + +func (Permission) Fields() []ent.Field { + return []ent.Field{ + field.String("code").Unique().MaxLen(64).Comment("权限编码,如 inbound:view"), + field.String("name").MaxLen(64).Comment("名称"), + field.String("type").Default("MENU").MaxLen(20).Comment("类型 MENU菜单/BUTTON按钮"), + field.String("path").Default("").MaxLen(128).Optional().Comment("前端路由(菜单类)"), + field.String("icon").Default("").MaxLen(64).Optional().Comment("图标(菜单类)"), + field.Int("sort").Default(0).Optional().Comment("排序"), + field.String("remark").Default("").MaxLen(255).Optional().Comment("备注"), + field.Int64("created_at").DefaultFunc(nowUnix).Comment("创建时间"), + field.Int64("updated_at").DefaultFunc(nowUnix).Comment("更新时间"), + } +} + +func (Permission) Indexes() []ent.Index { + return []ent.Index{index.Fields("code").Unique()} +} diff --git a/bj_power_wms/schema/role.go b/bj_power_wms/schema/role.go new file mode 100644 index 0000000..0142d2f --- /dev/null +++ b/bj_power_wms/schema/role.go @@ -0,0 +1,41 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +// Role 角色:承载菜单/按钮权限 +// 模型移植自 MES(schema/role.go),但按 WMS 约定调整: +// - 字段名 snake_case(由 tools/generate.go 统一转 camelCase 输出 JSON) +// - 时间字段用 Int64 unix 秒,与 WMS 其余表保持一致 +// - 与 MES 的差异:MES 的角色/权限为"系统预置只读",WMS 要求可维护,故支持增删改 +type Role struct { + ent.Schema +} + +func (Role) Annotations() []schema.Annotation { + return []schema.Annotation{entsql.Annotation{Table: "roles"}} +} + +func (Role) Fields() []ent.Field { + return []ent.Field{ + field.String("name").MaxLen(64).Comment("角色名称"), + field.String("code").Unique().MaxLen(64).Comment("角色编码,如 admin/operator/inspector"), + field.String("remark").Default("").MaxLen(255).Optional().Comment("备注"), + // 权限编码列表,如 inbound:view / inbound:create + field.JSON("permission_codes", []string{}).Optional().SchemaType(map[string]string{ + dialect.Postgres: "jsonb", + }).Comment("权限编码列表"), + field.Int64("created_at").DefaultFunc(nowUnix).Comment("创建时间"), + field.Int64("updated_at").DefaultFunc(nowUnix).Comment("更新时间"), + } +} + +func (Role) Indexes() []ent.Index { + return []ent.Index{index.Fields("code").Unique()} +} diff --git a/bj_power_wms/schema/user.go b/bj_power_wms/schema/user.go index 7339503..bf34ee0 100644 --- a/bj_power_wms/schema/user.go +++ b/bj_power_wms/schema/user.go @@ -18,7 +18,8 @@ func (User) Fields() []ent.Field { field.String("username").Unique().Comment("登录名"), field.String("password").Comment("密码(哈希)"), field.String("real_name").Optional().Comment("姓名"), - field.String("role").Default("operator").Comment("角色 admin/operator/inspector"), + field.String("role").Default("operator").Comment("角色 admin/operator/inspector(旧字段,权限数据化后由 role_id 决定,此字段仅作兼容/展示)"), + field.Int("role_id").Optional().Comment("角色ID,关联 roles 表;为空时回退按 role 字符串取权限"), field.String("dept").Optional().Comment("部门"), field.String("phone").Optional().Comment("电话"), field.Bool("is_active").Default(true).Comment("是否启用"), diff --git a/bj_power_wms_client/frontend/src/help.js b/bj_power_wms_client/frontend/src/help.js index 20bcbb4..06fe9d4 100644 --- a/bj_power_wms_client/frontend/src/help.js +++ b/bj_power_wms_client/frontend/src/help.js @@ -5,11 +5,20 @@ export const helpInbound = { title: '入库(来料入账)', overview: - '把到货的来料记入 WMS 库存。按管理类型分两种入库方式:\n· 结构件(螺丝/机加工件) → 按【批次】入库,一批多件;\n· 精密件(芯片/器件) → 按【SN 序列号】逐件扫码,可单件追溯。\n\n管理类型由 WMS 的"物料档案"决定(精密件/结构件),入库方式随之自动给出。\n入库是整个库存链路的第一环:入库(Held) → 质量检验(合格Z02) → 之后才能被出库锁定。', + '把到货的来料记入 WMS 库存。按管理类型分两种入库方式:\n· 结构件(螺丝/机加工件) → 按【批次】入库,一批多件;\n· 精密件(芯片/器件) → 按【SN 序列号】逐件扫码,可单件追溯。\n\n管理类型由 WMS 的"物料档案"决定(精密件/结构件),入库方式随之自动给出。\n入库是整个库存链路的第一环:入库(Held) → 质量检验(合格Z02) → 之后才能被出库锁定。\n\n页面分工(单一职责):\n· 入库管理:分页列表 + 查询条件(入库单号/物料编码/类型/关键字/时间) + 导出,结构件与精密件同表展示。\n· 批量入库:点本页「批量入库」按钮在新标签页打开,承载录入与 Excel 导入(本页不再含查询列表)。', sections: [ { - title: 'Tab1 结构件入库(按批次)', - overview: '适用于螺丝、机加工件等结构件,一次到货入一批。', + title: '入库管理(列表 / 查询 / 导出)', + overview: '分页展示全部入库单,结构件与精密件同表(用"类型"列区分)。支持按入库单号、物料编码、类型、关键字、入库时间筛选;可按当前条件导出 CSV。点行「明细」展开该单的批次号/SN 明细。', + fields: [ + { name: '查询条件', source: '本页顶部筛选区。', purpose: '缩小列表范围', fill: '可组合:入库单号(模糊)/物料编码(模糊)/类型(全部·结构件·精密件)/关键字(物料名称或单号)/入库时间区间' }, + { name: '导出', source: '按钮。后端 /inbound/export 按当前条件返回全部(不分页)。', purpose: '把筛选结果一次性导出为 CSV', fill: '点【导出】下载"入库单导出.csv"' }, + { name: '明细', source: '列表行内展开。', purpose: '查看该入库单的批次号/SN/数量明细', fill: '点行末「明细」或行首箭头展开' } + ] + }, + { + title: '批量入库(新标签页 · 结构件入库)', + overview: '由「入库管理」页的「批量入库」按钮在新标签页打开。适用于螺丝、机加工件等结构件,一次到货入一批。', fields: [ { name: '物料', source: '下拉选择。数据来自 WMS"物料档案"里类型为"结构件"的物料。', purpose: '入库的是什么物料;档案里必须存在才能选到', fill: '选择物料编码,如 SCREW-M3;选不到=还没建该物料档案' }, { name: '批次号', source: '留空系统自动生成(日期+序号);也可手工填。', purpose: '区别不同到货批次,实现先进先出(FIFO)', fill: '默认留空自动生成;供应商自带批号时可手填' }, @@ -20,8 +29,8 @@ export const helpInbound = { ] }, { - title: 'Tab2 精密件 SN 入库(逐件)', - overview: '适用于芯片、器件等需要单件追溯的来料,一件一个 SN。', + title: '批量入库(新标签页 · 精密件 SN 入库)', + overview: '同一新标签页的第二个页签。适用于芯片、器件等需要单件追溯的来料,一件一个 SN。', fields: [ { name: '物料', source: '下拉选择(必填)。来自"物料档案"类型为"精密件"的物料。', purpose: '入库的精密件物料', fill: '选择物料编码' }, { name: '区域', source: '下拉选择(必填)。来自"区域维护"。', purpose: '放到哪个库区', fill: '必填;新到货一般先放"待检"区' }, @@ -29,48 +38,57 @@ export const helpInbound = { ] }, { - title: 'Tab3 Excel 批量导入', - overview: '用于大批量结构件入库。列头顺序(首行忽略):物料编码 | 批次号(空自动生成) | 数量 | 生产日期 | 供应商 | 区域。', + title: '批量导入(各页签自带,非独立页面)', + overview: + '结构件页签与精密件 SN 页签各自带一个"批量导入"按钮,按本页签的管理类型导入,不再有独立的"Excel 批量导入"页。\n' + + '强约束:整表一次性全导入或全失败——后端先逐行校验(物料存在/数量>0/SN 不重复/区域必填),任一错则整体拒绝并列出错误行,不发生任何写入;全部通过才提交。\n' + + '结构件模板(首行忽略表头):物料编码 | 批次号(可空自动生成) | 数量 | 生产日期 | 供应商 | 区域 | 备注。\n' + + '精密件模板(首行忽略表头):物料编码 | SN | 区域 | 生产日期 | 供应商。', fields: [ - { name: '文件', source: '选择本地 .xlsx 文件。', purpose: '批量导入的物料清单', fill: '按列头顺序准备好 Excel,选择上传' } + { name: '文件', source: '选择本页签对应的 .xlsx 文件。', purpose: '批量导入的物料清单', fill: '按对应模板列头准备好 Excel,选择上传;导入结果(成功数/错误行)显示在页面下方' } ] } ] } export const helpOutbound = { - title: '出库(按工单领料)', + title: '出库管理(统一主表)', overview: - '仓库按工单台账为生产备料出库。系统强约束:单物料累计出库 ≤ 工单需求总量,超发走补料流程。\n可一次出完,也可分多次、分批由 AGV 配送到各 DOCK(配送节奏由仓库决定)。\n\n前置条件:必须先有"工单物料台账"(GOMES 工单+物料清单导入),且该物料在【合格区Z02】有足够库存。', + '所有出库都落在同一张「出库主表」(OutboundOrder),用"类型"区分,装箱信息(箱号/SN清单/合同号)也直接记在主表上,不再单独建装箱表。\n两个出库页签 + 一个记录页签:\n· 工单备料出库(MES):对接 MES 工单台账领料,强约束"单物料累计出库 ≤ 工单需求总量";未启用 MES 或工单未同步时,工单下拉可能为空,可直接手输工单号(需台账已同步)。\n· 通用出库:不依赖工单的手动出库(退料/样品/报废/发货),支持结构件批次与精密件 SN,填箱号即一并记录装箱;MES 不可用或无需挂靠工单时请用本页。\n· 出库记录:统一主表的全量查询与导出(一键导出 CSV,含装箱信息)。\n选用原则:有 MES 工单要按 BOM 领料 → 工单备料出库;无工单的自由出库/装箱发货 → 通用出库。', fields: [ - { name: '工单号', source: '手动输入。数据来自 MES 已建的工单及导入的物料台账。', purpose: '出库挂靠的工单,决定可领料总量与需求缺口', fill: '输入工单号回车,查询该工单的物料台账' }, - { name: '操作人', source: '登录账号自动带出。', purpose: '本次出库执行人,追溯用', fill: '自动,无需填' }, - { name: '目标工位', source: '手动填写。', purpose: '本次配送送达的接驳台/DOCK', fill: '如 DOCK-A,可空' }, - { name: '一键分配出库', source: '系统自动按 FIFO 分配。数据来自合格区Z02的批次库存。', purpose: '从合格区按先进先出凑够缺口并出库', fill: '点按钮,系统自动算批次并二次确认' } + { name: '备料出库-工单号', source: '手动输入。数据来自 MES 已建的工单及导入的物料台账。', purpose: '出库挂靠的工单,决定可领料总量与需求缺口', fill: '输入工单号回车,查询该工单的物料台账' }, + { name: '备料出库-目标工位', source: '手动填写。', purpose: '本次配送送达的接驳台/DOCK', fill: '如 DOCK-A,可空' }, + { name: '备料出库-一键分配出库', source: '系统自动按 FIFO 分配。数据来自合格区Z02的批次库存。', purpose: '从合格区按先进先出凑够缺口并出库', fill: '点按钮,系统自动算批次并二次确认' }, + { name: '通用出库-物料/类型', source: '下拉选择物料;类型选"结构件(批次)"或"精密件(SN)"。', purpose: '决定走批次扣减还是 SN 扣减', fill: '选物料后选类型;批次填批次号+数量,SN 扫入 SN 列表' }, + { name: '通用出库-箱号', source: '手动填写(选填)。', purpose: '整箱发货时填写,装箱信息随出库单记录(无需再单独录入装箱)', fill: '填箱号后,本出库单即带装箱属性,可在"出库记录"按箱号追溯' }, + { name: '通用出库-合同号', source: '手动填写(选填)。', purpose: '关联合同,便于按合同追溯', fill: '可空' }, + { name: '出库记录-导出 CSV', source: '按钮操作。', purpose: '把统一主表当前筛选结果一次导出为 CSV(含箱号/装箱SN)', fill: '点【导出 CSV】下载全部出库记录' } ] } export const helpInventory = { title: '库存查询', overview: - '查看当前库存:结构件按批次台账(数量/锁定/区域),精密件按 SN 序列号(状态/区域)。\n数据由入库、出库、盘点等业务实时维护,本页只读查询。', + '查看当前库存:结构件按批次台账(数量/锁定/区域),精密件按 SN 序列号(状态/区域)。\n数据由入库、出库、盘点等业务实时维护,本页只读查询。\n\n三个层级概念(自下而上):\n· SN 序列号:精密件单件唯一码,可逐件追溯。\n· 批次号:同物料、同一次到货的库存聚合标识(如 B20260901xxxx),一个批次可含多件。\n· 入库单号(IBxxx):一次到货/入库动作的凭证,一个入库单可包含多个批次或多个 SN(以及它们的明细)。\n即:入库单 → 批次/SN → 库存行。库存行上的"入库单号"即它的来源凭证,点单号可跳转入库页看该单完整明细。', fields: [ { name: '物料编码', source: '筛选条件。', purpose: '只看某物料', fill: '输入编码,可空=全部' }, { name: '库存类型', source: '单选(批次 / SN 序列)。', purpose: '看批次台账还是 SN 序列,各自独立分页', fill: '批次 / SN 序列' }, - { name: '关键字', source: '筛选条件。', purpose: '按批次号/物料名称/SN 模糊过滤', fill: '输入关键字,可空' } + { name: '关键字', source: '筛选条件。', purpose: '按批次号/物料名称/SN 模糊过滤', fill: '输入关键字,可空' }, + { name: '入库单号', source: '筛选条件 + 列表列。数据来自每次入库生成的 IBxxx 凭证。', purpose: '追溯某批库存"来自哪次入库";与批次号不同:批次号是库存聚合标识,入库单号是入库动作凭证(一个单可含多批次/多SN)', fill: '输入 IB 单号过滤,或点列表里的单号跳转入库明细' } ] } export const helpInspection = { title: '质量检验(来料检)', overview: - '对入库的未检物料/SN 做检验:把"未检"翻转为【合格】或【不合格】。\n检验只修改"质量状态"字段,与物料/SN 的存放区域无关。\n合格品才能参与出库与锁库(库存校验只取质量状态=合格的批次)。', + '对入库的未检物料/SN 做检验:把"未检"翻转为【合格】或【不合格】。\n检验只修改"质量状态"字段,与物料/SN 的存放区域无关。\n合格品才能参与出库与锁库(库存校验只取质量状态=合格的批次)。\n\n录入方式:单条与批量已合并为同一处——无论是扫码枪连续扫、还是从"库存"下拉直接选,都先进入下方"已选清单",点一次"提交检验"统一翻转。\n编号是否真实存在会即时校验:找不到对应库存记录的编号会直接报错,不会"提示成功但库存仍是未检"。', fields: [ - { name: '目标类型', source: '单选。', purpose: '检验对象是批次还是 SN', fill: '批次 BATCH / 序列号 SN' }, + { name: '目标类型', source: '单选,决定录入框标题与可选库存范围。', purpose: '检验对象是批次(结构件)还是 SN(精密件)', fill: '批次 BATCH / 序列号 SN;切换时会自动刷新"从库存选"下拉' }, { name: '检验结论', source: '单选。', purpose: '判定结果', fill: '合格 / 不合格' }, { name: '检验员', source: '手动填写(默认当前用户)。', purpose: '谁检验的,追溯用', fill: '检验员姓名' }, - { name: '扫码输入', source: '扫码枪。来自批次号/SN条码。', purpose: '单个待检的批次号或 SN', fill: '扫批次号或 SN,回车提交' }, - { name: '批量编号', source: '扫码枪连续录入。', purpose: '一次性翻转多个目标的检验状态', fill: '每行一个编号' } + { name: '从库存选批次号/SN', source: '下拉选择,数据来自当前库存(按目标类型过滤)。', purpose: '避免手输编号、防止输错', fill: '在库存里挑待检的批次号/SN,自动加入清单' }, + { name: '录入批次号/SN', source: '扫码枪/粘贴。来自批次号/SN条码。', purpose: '单条或多条待检编号', fill: '扫入或粘贴后点【录入到列表】,多编号用逗号/分号/空格/回车分隔' }, + { name: '已选清单', source: '本页待提交列表。', purpose: '统一查看、可逐个删除', fill: '列在此处的编号,点【提交检验】一次性翻转' } ] } @@ -87,19 +105,6 @@ export const helpStocktake = { ] } -export const helpPackage = { - title: '装箱管理(箱号 ↔ SN)', - overview: - '把若干成品/精密件 SN 装入同一个箱号,形成可追溯的包装箱,用于发货、入库、整箱追溯。\n数据链路:拣选出待包装的 SN → 扫进同一箱号 → 一个箱号关联多个 SN → 后续按箱号出库/发货/追溯。', - fields: [ - { name: '箱号', source: '扫码枪/手动输入,箱子上的条码或手贴码。', purpose: '包装箱唯一标识,一箱一个号', fill: '扫描或手输箱号;同一箱号不可重复使用' }, - { name: '物料', source: '下拉选择(可空)。来自物料档案。', purpose: '箱内物料的类型;建议同一箱只装一种物料', fill: '可选;选择后建议只扫该物料 SN' }, - { name: '合同号', source: '手动填写(选填)。', purpose: '关联销售/采购合同,便于按合同追溯', fill: '可空;按合同装箱时填写' }, - { name: '操作人', source: '登录账号自动带出。', purpose: '装箱人,追溯用', fill: '自动' }, - { name: 'SN 录入', source: '扫码枪连续扫码。来自成品/精密件 SN 条码。', purpose: '装进箱内的 SN 清单', fill: '扫入 SN 后点【录入到列表】加入清单,回车只是换行;支持逗号/分号/顿号/空格/回车分隔' } - ] -} - export const helpSemi = { title: '半成品/成品(流转)', overview: diff --git a/bj_power_wms_client/frontend/src/layouts/MainLayout.vue b/bj_power_wms_client/frontend/src/layouts/MainLayout.vue index 3a73080..dbddfc3 100644 --- a/bj_power_wms_client/frontend/src/layouts/MainLayout.vue +++ b/bj_power_wms_client/frontend/src/layouts/MainLayout.vue @@ -4,7 +4,7 @@ import { useRoute, useRouter } from 'vue-router' import { ElMessage } from 'element-plus' import { HomeFilled, Download, Upload, Search, CircleCheck, List, - Box, Tickets, Monitor, EditPen, Fold, Expand, Location, Goods + Box, Tickets, Monitor, EditPen, Fold, Expand, Location, Goods, Key, DocumentChecked } from '@element-plus/icons-vue' import { getUser, getToken, logout, setSession } from '../utils/auth' import request from '../utils/request' @@ -26,6 +26,11 @@ async function loadMe() { me.value = u setSession(getToken(), u) // 刷新本地用户(含最新 permissionCodes/角色) } catch { /* 用登录时写入的 user 兜底 */ } + // 幂等初始化 RBAC 种子:权限码与内置角色仅首次创建,已存在则跳过。 + // 管理员登录后自动执行,保证前端菜单/角色页有数据。 + try { + await request.post('/rbac/seed', {}) + } catch { /* 无权限或已初始化,忽略 */ } } // ===== 响应式侧边栏:桌面可折叠,移动端抽屉 ===== @@ -64,16 +69,17 @@ onBeforeUnmount(() => window.removeEventListener('resize', onScreenChange)) const defaultMenus = [ { path: '/', title: '工作台', icon: HomeFilled, code: 'dashboard:view' }, { path: '/inbound', title: '入库管理', icon: Download, code: 'inbound:view' }, - { path: '/outbound', title: '备料出库', icon: Upload, code: 'outbound:view' }, + { path: '/outbound', title: '出库管理', icon: Upload, code: 'outbound:view' }, { path: '/inventory', title: '库存查询', icon: Search, code: 'inventory:view' }, { path: '/inspection', title: '质量检验', icon: CircleCheck, code: 'inspection:view' }, + { path: '/inspection-query', title: '检验记录', icon: DocumentChecked, code: 'inspection:view' }, { path: '/stocktake', title: '库存盘点', icon: List, code: 'stocktake:view' }, { path: '/semi', title: '半成品/成品', icon: Box, code: 'semi:view' }, - { path: '/package', title: '装箱管理', icon: Box, code: 'package:view' }, { path: '/ledger', title: '备料台账', icon: Tickets, code: 'ledger:view' }, { path: '/zone', title: '区域维护', icon: Location, code: 'zone:view' }, { path: '/material', title: '物料档案', icon: Goods, code: 'material:view' }, - { path: '/users', title: '账号管理', icon: EditPen, code: 'user:manage' } + { path: '/users', title: '账号管理', icon: EditPen, code: 'user:manage' }, + { path: '/roles', title: '角色管理', icon: Key, code: 'role:manage' } ] // 按当前用户权限码过滤菜单(无 code 的常驻;user:manage 仅管理员可见) @@ -81,6 +87,17 @@ const menus = computed(() => defaultMenus.filter((m) => !m.code || permissionCodes.value.includes(m.code)) ) +// keep-alive 缓存列表页组件:从路由 meta.keepAlive 收集组件名 +// (返回列表页时保留筛选/页码/已加载数据,避免重复请求) +const cachedNames = computed(() => { + const names = [] + for (const r of router.getRoutes()) { + const meta = r.meta || {} + if (meta.keepAlive && meta.componentName) names.push(meta.componentName) + } + return names +}) + // 打开当前页面帮助(各页面 PageHelp 监听 wms:open-page-help 事件弹出抽屉) function openHelp() { window.dispatchEvent(new CustomEvent('wms:open-page-help')) @@ -146,7 +163,11 @@ function onLogout() { - + + + + + diff --git a/bj_power_wms_client/frontend/src/pages/BaseData.vue b/bj_power_wms_client/frontend/src/pages/BaseData.vue index 4cf17d8..e2ec0ae 100644 --- a/bj_power_wms_client/frontend/src/pages/BaseData.vue +++ b/bj_power_wms_client/frontend/src/pages/BaseData.vue @@ -1,7 +1,9 @@ + \ No newline at end of file diff --git a/bj_power_wms_client/frontend/src/pages/Dashboard.vue b/bj_power_wms_client/frontend/src/pages/Dashboard.vue index 1c9076d..abcab11 100644 --- a/bj_power_wms_client/frontend/src/pages/Dashboard.vue +++ b/bj_power_wms_client/frontend/src/pages/Dashboard.vue @@ -1,4 +1,5 @@