feat:多项功能优化

This commit is contained in:
zhoujianjin
2026-09-18 18:54:54 +08:00
parent 672cd23329
commit 543655d441
48 changed files with 1289 additions and 447 deletions
+38 -3
View File
@@ -255,6 +255,8 @@ type StationVO struct {
FlowName string `json:"flowName"`
StationType string `json:"stationType"`
Status string `json:"status"`
IsBuiltin bool `json:"isBuiltin"`
HasDock bool `json:"hasDock"`
}
func (s *Service) ListStations(ctx context.Context) ([]*StationVO, error) {
@@ -269,7 +271,7 @@ func (s *Service) ListStations(ctx context.Context) ([]*StationVO, error) {
}
out := make([]*StationVO, 0, len(stas))
for _, st := range stas {
vo := &StationVO{Id: st.ID, StationNo: st.StationNo, Name: st.Name, FlowId: st.FlowId, StationType: st.StationType, Status: st.Status}
vo := &StationVO{Id: st.ID, StationNo: st.StationNo, Name: st.Name, FlowId: st.FlowId, StationType: st.StationType, Status: st.Status, IsBuiltin: st.IsBuiltin, HasDock: st.HasDock}
if f, ok := flowMap[st.FlowId]; ok {
vo.FlowName = f.Name
}
@@ -283,6 +285,9 @@ func (s *Service) ListStations(ctx context.Context) ([]*StationVO, error) {
// - 工位号不存在 → 新增工位;新增的工位号由用户自定义,允许扩展 14、15…(虚拟/物理均可)
//
// 工位数量以数据库为准,前端下拉随 station 表自动增减;虚拟工位(0/13/14...)不连 PLC、仅记录。
// 内置工位(种子/初始化数据,is_builtin=true)需连 PLC 并必须按工位号顺序流转,
// 不允许手动更改工位类型;页面新增的工位一律为非内置,可改类型、可删除。
// 「是否有接驳台」对应实体位置,由内置数据给定,不接收页面入参。
func (s *Service) SaveStation(ctx context.Context, req StationReq, operator string) error {
if req.StationNo < 0 {
return errors.New("工位号非法(需 ≥ 0")
@@ -304,7 +309,10 @@ func (s *Service) SaveStation(ctx context.Context, req StationReq, operator stri
}
}
cr := s.ctx.EntClient.Station.Create().
SetStationNo(req.StationNo).SetName(req.Name).SetStationType(stype).SetStatus("ENABLED")
SetStationNo(req.StationNo).SetName(req.Name).SetStationType(stype).SetStatus("ENABLED").
// 页面「新增工位」创建的是非内置工位(可改类型、可删除);内置工位只能由种子/初始化数据产生。
// 是否有接驳台对应实体位置,由内置数据给定,页面新增时一律为 false 且不可手改。
SetIsBuiltin(false).SetHasDock(false)
if req.FlowId != nil && *req.FlowId > 0 {
flow, fErr := s.ctx.EntClient.ProcessFlow.Get(ctx, *req.FlowId)
if fErr != nil {
@@ -330,7 +338,13 @@ func (s *Service) SaveStation(ctx context.Context, req StationReq, operator stri
if t != "LINE" && t != "OFFLINE" {
return errors.New("工位类型仅支持 LINE/OFFLINE")
}
upd.SetStationType(t)
// 内置工位对应实体产线固定位置(含 PLC 通讯与顺序流转),工位类型不可手动更改。
if st.IsBuiltin && t != st.StationType {
return errors.New("内置工位不允许修改工位类型")
}
if !st.IsBuiltin {
upd.SetStationType(t)
}
}
if req.FlowId != nil {
fid := *req.FlowId
@@ -355,6 +369,27 @@ func (s *Service) SaveStation(ctx context.Context, req StationReq, operator stri
return nil
}
// DeleteStation 删除工位:内置工位不允许删除(对应实体产线位置,需连 PLC 且必须按顺序流转);
// 非内置工位(页面新增的)允许删除。
func (s *Service) DeleteStation(ctx context.Context, id int, operator string) error {
if id <= 0 {
return errors.New("缺少 id")
}
st, err := s.ctx.EntClient.Station.Get(ctx, id)
if err != nil {
return errors.New("工位不存在")
}
if st.IsBuiltin {
return errors.New("内置工位不允许删除")
}
if err := s.ctx.EntClient.Station.DeleteOneID(st.ID).Exec(ctx); err != nil {
return err
}
s.ctx.EventLog.Write(ctx, "station.delete", "", operator, "station", "", "删除工位",
map[string]any{"stationNo": st.StationNo, "name": st.Name})
return nil
}
// SetFlowStatus 工艺流程启用/停用。
// 新语义:绑定关系由「保存流程」显式维护(一个流程可绑多工位),启停只切换流程状态,
// 不再自动解绑/绑定工位;停用流程对已绑定工位不可用(工位取步骤时按 ACTIVE 过滤)。