feat: 会话令牌与守卫、看板组件及工位终端功能完善

- 用户表扩展:MES/WMS user 实体新增字段,新增 active_token 迁移 SQL(2026-11-11)
- 会话机制:MES 新增 session_guard,重构 token/auth/jwt/perm 与路由;WMS/工作站同步令牌续签与鉴权
- 看板(board):调整 MES 看板产线/生产/侧栏/仓库组件及样式;WMS 看板展示页同步调整
- 工位终端后端:完善报警流、绑定、PLC 对账、拧紧、proxy、上报、站点告警/操作等 handler,补充 mes client/store
- 工位终端前端:登录/主界面/各操作面板调整,新增滚动分页与多语言 yaml 文案,刷新构建产物
- MES 业务:新增流程链 logic,调整待审核/产能支撑/产品工艺/设置页、PLC 监控与帮助文档,刷新构建产物
- 更新问题记录文档
This commit is contained in:
SunYF
2026-11-11 14:36:16 +08:00
parent 619fc8983d
commit 7b7d27d150
79 changed files with 2056 additions and 471 deletions
+1
View File
@@ -1304,6 +1304,7 @@ var (
{Name: "workstation_password", Type: field.TypeString, Nullable: true, Size: 128, Comment: "工位终端密码(bcrypt)"},
{Name: "status", Type: field.TypeString, Size: 20, Default: "ENABLED"},
{Name: "last_login_at", Type: field.TypeInt64, Nullable: true, Comment: "最近登录时间(unix秒,后台登录更新;工位终端登录不计)"},
{Name: "active_token", Type: field.TypeString, Nullable: true, Comment: "后台登录会话标识(SID),互踢用;空=无生效后台会话"},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
}
+74 -1
View File
@@ -36325,6 +36325,7 @@ type UserMutation struct {
status *string
lastLoginAt *int64
addlastLoginAt *int64
activeToken *string
createdAt *time.Time
updatedAt *time.Time
clearedFields map[string]struct{}
@@ -36806,6 +36807,55 @@ func (m *UserMutation) ResetLastLoginAt() {
delete(m.clearedFields, user.FieldLastLoginAt)
}
// SetActiveToken sets the "activeToken" field.
func (m *UserMutation) SetActiveToken(s string) {
m.activeToken = &s
}
// ActiveToken returns the value of the "activeToken" field in the mutation.
func (m *UserMutation) ActiveToken() (r string, exists bool) {
v := m.activeToken
if v == nil {
return
}
return *v, true
}
// OldActiveToken returns the old "activeToken" 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) OldActiveToken(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldActiveToken is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldActiveToken requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldActiveToken: %w", err)
}
return oldValue.ActiveToken, nil
}
// ClearActiveToken clears the value of the "activeToken" field.
func (m *UserMutation) ClearActiveToken() {
m.activeToken = nil
m.clearedFields[user.FieldActiveToken] = struct{}{}
}
// ActiveTokenCleared returns if the "activeToken" field was cleared in this mutation.
func (m *UserMutation) ActiveTokenCleared() bool {
_, ok := m.clearedFields[user.FieldActiveToken]
return ok
}
// ResetActiveToken resets all changes to the "activeToken" field.
func (m *UserMutation) ResetActiveToken() {
m.activeToken = nil
delete(m.clearedFields, user.FieldActiveToken)
}
// SetCreatedAt sets the "createdAt" field.
func (m *UserMutation) SetCreatedAt(t time.Time) {
m.createdAt = &t
@@ -36925,7 +36975,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)
}
@@ -36950,6 +37000,9 @@ func (m *UserMutation) Fields() []string {
if m.lastLoginAt != nil {
fields = append(fields, user.FieldLastLoginAt)
}
if m.activeToken != nil {
fields = append(fields, user.FieldActiveToken)
}
if m.createdAt != nil {
fields = append(fields, user.FieldCreatedAt)
}
@@ -36980,6 +37033,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
return m.Status()
case user.FieldLastLoginAt:
return m.LastLoginAt()
case user.FieldActiveToken:
return m.ActiveToken()
case user.FieldCreatedAt:
return m.CreatedAt()
case user.FieldUpdatedAt:
@@ -37009,6 +37064,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
return m.OldStatus(ctx)
case user.FieldLastLoginAt:
return m.OldLastLoginAt(ctx)
case user.FieldActiveToken:
return m.OldActiveToken(ctx)
case user.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case user.FieldUpdatedAt:
@@ -37078,6 +37135,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error {
}
m.SetLastLoginAt(v)
return nil
case user.FieldActiveToken:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetActiveToken(v)
return nil
case user.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
@@ -37158,6 +37222,9 @@ func (m *UserMutation) ClearedFields() []string {
if m.FieldCleared(user.FieldLastLoginAt) {
fields = append(fields, user.FieldLastLoginAt)
}
if m.FieldCleared(user.FieldActiveToken) {
fields = append(fields, user.FieldActiveToken)
}
if m.FieldCleared(user.FieldUpdatedAt) {
fields = append(fields, user.FieldUpdatedAt)
}
@@ -37184,6 +37251,9 @@ func (m *UserMutation) ClearField(name string) error {
case user.FieldLastLoginAt:
m.ClearLastLoginAt()
return nil
case user.FieldActiveToken:
m.ClearActiveToken()
return nil
case user.FieldUpdatedAt:
m.ClearUpdatedAt()
return nil
@@ -37219,6 +37289,9 @@ func (m *UserMutation) ResetField(name string) error {
case user.FieldLastLoginAt:
m.ResetLastLoginAt()
return nil
case user.FieldActiveToken:
m.ResetActiveToken()
return nil
case user.FieldCreatedAt:
m.ResetCreatedAt()
return nil
+2 -2
View File
@@ -2099,11 +2099,11 @@ func init() {
// user.StatusValidator is a validator for the "status" field. It is called by the builders before save.
user.StatusValidator = userDescStatus.Validators[0].(func(string) error)
// userDescCreatedAt is the schema descriptor for createdAt field.
userDescCreatedAt := userFields[9].Descriptor()
userDescCreatedAt := userFields[10].Descriptor()
// user.DefaultCreatedAt holds the default value on creation for the createdAt field.
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
// userDescUpdatedAt is the schema descriptor for updatedAt field.
userDescUpdatedAt := userFields[10].Descriptor()
userDescUpdatedAt := userFields[11].Descriptor()
// user.DefaultUpdatedAt holds the default value on creation for the updatedAt field.
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time)
// user.UpdateDefaultUpdatedAt holds the default value on update for the updatedAt field.
+12 -1
View File
@@ -33,6 +33,8 @@ type User struct {
Status string `json:"status,omitempty"`
// 最近登录时间(unix秒,后台登录更新;工位终端登录不计)
LastLoginAt *int64 `json:"lastLoginAt,omitempty"`
// 后台登录会话标识(SID),互踢用;空=无生效后台会话
ActiveToken string `json:"activeToken,omitempty"`
// CreatedAt holds the value of the "createdAt" field.
CreatedAt time.Time `json:"createdAt,omitempty"`
// UpdatedAt holds the value of the "updatedAt" field.
@@ -49,7 +51,7 @@ func (*User) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool)
case user.FieldID, user.FieldRoleId, user.FieldLastLoginAt:
values[i] = new(sql.NullInt64)
case user.FieldUsername, user.FieldPassword, user.FieldName, user.FieldWorkstationPassword, user.FieldStatus:
case user.FieldUsername, user.FieldPassword, user.FieldName, user.FieldWorkstationPassword, user.FieldStatus, user.FieldActiveToken:
values[i] = new(sql.NullString)
case user.FieldCreatedAt, user.FieldUpdatedAt:
values[i] = new(sql.NullTime)
@@ -123,6 +125,12 @@ func (_m *User) assignValues(columns []string, values []any) error {
_m.LastLoginAt = new(int64)
*_m.LastLoginAt = value.Int64
}
case user.FieldActiveToken:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field activeToken", values[i])
} else if value.Valid {
_m.ActiveToken = value.String
}
case user.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field createdAt", values[i])
@@ -198,6 +206,9 @@ func (_m *User) String() string {
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("activeToken=")
builder.WriteString(_m.ActiveToken)
builder.WriteString(", ")
builder.WriteString("createdAt=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
+8
View File
@@ -29,6 +29,8 @@ const (
FieldStatus = "status"
// FieldLastLoginAt holds the string denoting the lastloginat field in the database.
FieldLastLoginAt = "last_login_at"
// FieldActiveToken holds the string denoting the activetoken field in the database.
FieldActiveToken = "active_token"
// FieldCreatedAt holds the string denoting the createdat field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updatedat field in the database.
@@ -48,6 +50,7 @@ var Columns = []string{
FieldWorkstationPassword,
FieldStatus,
FieldLastLoginAt,
FieldActiveToken,
FieldCreatedAt,
FieldUpdatedAt,
}
@@ -137,6 +140,11 @@ func ByLastLoginAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLastLoginAt, opts...).ToFunc()
}
// ByActiveToken orders the results by the activeToken field.
func ByActiveToken(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldActiveToken, opts...).ToFunc()
}
// ByCreatedAt orders the results by the createdAt field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
+80
View File
@@ -94,6 +94,11 @@ func LastLoginAt(v int64) predicate.User {
return predicate.User(sql.FieldEQ(FieldLastLoginAt, v))
}
// ActiveToken applies equality check predicate on the "activeToken" field. It's identical to ActiveTokenEQ.
func ActiveToken(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldActiveToken, v))
}
// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
@@ -549,6 +554,81 @@ func LastLoginAtNotNil() predicate.User {
return predicate.User(sql.FieldNotNull(FieldLastLoginAt))
}
// ActiveTokenEQ applies the EQ predicate on the "activeToken" field.
func ActiveTokenEQ(v string) predicate.User {
return predicate.User(sql.FieldEQ(FieldActiveToken, v))
}
// ActiveTokenNEQ applies the NEQ predicate on the "activeToken" field.
func ActiveTokenNEQ(v string) predicate.User {
return predicate.User(sql.FieldNEQ(FieldActiveToken, v))
}
// ActiveTokenIn applies the In predicate on the "activeToken" field.
func ActiveTokenIn(vs ...string) predicate.User {
return predicate.User(sql.FieldIn(FieldActiveToken, vs...))
}
// ActiveTokenNotIn applies the NotIn predicate on the "activeToken" field.
func ActiveTokenNotIn(vs ...string) predicate.User {
return predicate.User(sql.FieldNotIn(FieldActiveToken, vs...))
}
// ActiveTokenGT applies the GT predicate on the "activeToken" field.
func ActiveTokenGT(v string) predicate.User {
return predicate.User(sql.FieldGT(FieldActiveToken, v))
}
// ActiveTokenGTE applies the GTE predicate on the "activeToken" field.
func ActiveTokenGTE(v string) predicate.User {
return predicate.User(sql.FieldGTE(FieldActiveToken, v))
}
// ActiveTokenLT applies the LT predicate on the "activeToken" field.
func ActiveTokenLT(v string) predicate.User {
return predicate.User(sql.FieldLT(FieldActiveToken, v))
}
// ActiveTokenLTE applies the LTE predicate on the "activeToken" field.
func ActiveTokenLTE(v string) predicate.User {
return predicate.User(sql.FieldLTE(FieldActiveToken, v))
}
// ActiveTokenContains applies the Contains predicate on the "activeToken" field.
func ActiveTokenContains(v string) predicate.User {
return predicate.User(sql.FieldContains(FieldActiveToken, v))
}
// ActiveTokenHasPrefix applies the HasPrefix predicate on the "activeToken" field.
func ActiveTokenHasPrefix(v string) predicate.User {
return predicate.User(sql.FieldHasPrefix(FieldActiveToken, v))
}
// ActiveTokenHasSuffix applies the HasSuffix predicate on the "activeToken" field.
func ActiveTokenHasSuffix(v string) predicate.User {
return predicate.User(sql.FieldHasSuffix(FieldActiveToken, v))
}
// ActiveTokenIsNil applies the IsNil predicate on the "activeToken" field.
func ActiveTokenIsNil() predicate.User {
return predicate.User(sql.FieldIsNull(FieldActiveToken))
}
// ActiveTokenNotNil applies the NotNil predicate on the "activeToken" field.
func ActiveTokenNotNil() predicate.User {
return predicate.User(sql.FieldNotNull(FieldActiveToken))
}
// ActiveTokenEqualFold applies the EqualFold predicate on the "activeToken" field.
func ActiveTokenEqualFold(v string) predicate.User {
return predicate.User(sql.FieldEqualFold(FieldActiveToken, v))
}
// ActiveTokenContainsFold applies the ContainsFold predicate on the "activeToken" field.
func ActiveTokenContainsFold(v string) predicate.User {
return predicate.User(sql.FieldContainsFold(FieldActiveToken, v))
}
// CreatedAtEQ applies the EQ predicate on the "createdAt" field.
func CreatedAtEQ(v time.Time) predicate.User {
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
+18
View File
@@ -116,6 +116,20 @@ func (_c *UserCreate) SetNillableLastLoginAt(v *int64) *UserCreate {
return _c
}
// SetActiveToken sets the "activeToken" field.
func (_c *UserCreate) SetActiveToken(v string) *UserCreate {
_c.mutation.SetActiveToken(v)
return _c
}
// SetNillableActiveToken sets the "activeToken" field if the given value is not nil.
func (_c *UserCreate) SetNillableActiveToken(v *string) *UserCreate {
if v != nil {
_c.SetActiveToken(*v)
}
return _c
}
// SetCreatedAt sets the "createdAt" field.
func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate {
_c.mutation.SetCreatedAt(v)
@@ -321,6 +335,10 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec.SetField(user.FieldLastLoginAt, field.TypeInt64, value)
_node.LastLoginAt = &value
}
if value, ok := _c.mutation.ActiveToken(); ok {
_spec.SetField(user.FieldActiveToken, field.TypeString, value)
_node.ActiveToken = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
+52
View File
@@ -173,6 +173,26 @@ func (_u *UserUpdate) ClearLastLoginAt() *UserUpdate {
return _u
}
// SetActiveToken sets the "activeToken" field.
func (_u *UserUpdate) SetActiveToken(v string) *UserUpdate {
_u.mutation.SetActiveToken(v)
return _u
}
// SetNillableActiveToken sets the "activeToken" field if the given value is not nil.
func (_u *UserUpdate) SetNillableActiveToken(v *string) *UserUpdate {
if v != nil {
_u.SetActiveToken(*v)
}
return _u
}
// ClearActiveToken clears the value of the "activeToken" field.
func (_u *UserUpdate) ClearActiveToken() *UserUpdate {
_u.mutation.ClearActiveToken()
return _u
}
// SetUpdatedAt sets the "updatedAt" field.
func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate {
_u.mutation.SetUpdatedAt(v)
@@ -313,6 +333,12 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if _u.mutation.LastLoginAtCleared() {
_spec.ClearField(user.FieldLastLoginAt, field.TypeInt64)
}
if value, ok := _u.mutation.ActiveToken(); ok {
_spec.SetField(user.FieldActiveToken, field.TypeString, value)
}
if _u.mutation.ActiveTokenCleared() {
_spec.ClearField(user.FieldActiveToken, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}
@@ -485,6 +511,26 @@ func (_u *UserUpdateOne) ClearLastLoginAt() *UserUpdateOne {
return _u
}
// SetActiveToken sets the "activeToken" field.
func (_u *UserUpdateOne) SetActiveToken(v string) *UserUpdateOne {
_u.mutation.SetActiveToken(v)
return _u
}
// SetNillableActiveToken sets the "activeToken" field if the given value is not nil.
func (_u *UserUpdateOne) SetNillableActiveToken(v *string) *UserUpdateOne {
if v != nil {
_u.SetActiveToken(*v)
}
return _u
}
// ClearActiveToken clears the value of the "activeToken" field.
func (_u *UserUpdateOne) ClearActiveToken() *UserUpdateOne {
_u.mutation.ClearActiveToken()
return _u
}
// SetUpdatedAt sets the "updatedAt" field.
func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne {
_u.mutation.SetUpdatedAt(v)
@@ -655,6 +701,12 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
if _u.mutation.LastLoginAtCleared() {
_spec.ClearField(user.FieldLastLoginAt, field.TypeInt64)
}
if value, ok := _u.mutation.ActiveToken(); ok {
_spec.SetField(user.FieldActiveToken, field.TypeString, value)
}
if _u.mutation.ActiveTokenCleared() {
_spec.ClearField(user.FieldActiveToken, field.TypeString)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
}