feat&refactor: 完成多模块功能迭代与配置优化
本次提交覆盖多个业务模块的功能完善与体验优化:
1. **鉴权与配置调整**:
- 统一JWT滑动续签逻辑,简化Token存储,移除RefreshToken相关冗余代码
- 调整多项目配置文件中JWT过期时间为3600秒,统一会话闲置窗口
- 工位配置放开1~12限制,改为仅校验大于0
2. **术语统一替换**:全链路将"精密件"替换为"电气件",修正物料管理描述
3. **功能新增**:
- 新增工位类型、工艺路线与产线点位台账模块
- 添加工艺PDF预览面板、工位终端代理转发接口
- 新增操作日志按操作人列表筛选、工位登出日志记录
- 新增PLC移料指令与产线点位状态管理
4. **业务流程优化**:
- 调整BOM物料删除校验逻辑,优化工单备料计算
- 补充物料图号、检测单号等追溯字段
- 完善工艺流程图与工位绑定关系说明
- 优化前端页面文案与交互细节
5. **代码规范与维护**:
- 新增通用工具函数与前端静态资源
- 整理路由权限与中间件逻辑
- 修复部分接口与配置的不兼容问题
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
@@ -17,8 +19,8 @@ type WorkOrderReq struct {
|
||||
Id int `json:"id"`
|
||||
WorkOrderNo string `json:"workOrderNo"`
|
||||
ProductTypeId int `json:"productTypeId"`
|
||||
RouteId int `json:"routeId"`
|
||||
ProductCode string `json:"productCode"`
|
||||
BomName string `json:"bomName"` // 建单选定的 BOM 名称(同型号多份并存;空=「默认」)
|
||||
ProductName string `json:"productName"`
|
||||
Quantity int `json:"quantity"`
|
||||
ProcessSeq string `json:"processSeq"`
|
||||
@@ -27,27 +29,6 @@ type WorkOrderReq struct {
|
||||
PlanEnd string `json:"planEnd"`
|
||||
}
|
||||
|
||||
// validateBomName 校验该产品型号下是否存在指定名称的 BOM(型号下无任何 BOM 时放行,允许先建单后补 BOM)
|
||||
func (s *Service) validateBomName(ctx context.Context, productCode, bomName string) error {
|
||||
if productCode == "" {
|
||||
return nil
|
||||
}
|
||||
names, err := s.ListBomNames(ctx, productCode)
|
||||
if err != nil {
|
||||
return nil // 查询异常不阻塞建单(与 WMS 降级策略同思路)
|
||||
}
|
||||
if len(names) == 0 {
|
||||
return nil
|
||||
}
|
||||
target := bomNameOrDefault(bomName)
|
||||
for _, n := range names {
|
||||
if n.BomName == target {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("产品型号 %s 下不存在名为「%s」的BOM,请先在物料清单中创建", productCode, target)
|
||||
}
|
||||
|
||||
// CreateWorkOrder 创建工单(状态恒 CREATED,后续用状态流转按钮推进)
|
||||
func (s *Service) CreateWorkOrder(ctx context.Context, req WorkOrderReq, operator string) error {
|
||||
if req.WorkOrderNo == "" {
|
||||
@@ -66,23 +47,38 @@ func (s *Service) CreateWorkOrder(ctx context.Context, req WorkOrderReq, operato
|
||||
if status != "CREATED" {
|
||||
status = "CREATED" // 创建恒为已创建;不允许直接创建到后续状态
|
||||
}
|
||||
if req.ProcessSeq == "" {
|
||||
req.ProcessSeq = FullProcessSeq
|
||||
} else if err := ValidateProcessSeq(req.ProcessSeq); err != nil {
|
||||
return err
|
||||
}
|
||||
req.ProcessSeq = NormalizeProcessSeq(req.ProcessSeq)
|
||||
if err := s.validateBomName(ctx, req.ProductCode, req.BomName); err != nil {
|
||||
return err
|
||||
routeSnapshot := []map[string]any{}
|
||||
if req.RouteId > 0 {
|
||||
route, rerr := s.GetRoute(ctx, req.RouteId)
|
||||
if rerr != nil {
|
||||
return rerr
|
||||
}
|
||||
snapshot, lineStations := s.BuildRouteSnapshot(route)
|
||||
routeSnapshot = snapshot
|
||||
if len(lineStations) > 0 {
|
||||
parts := make([]string, 0, len(lineStations))
|
||||
for _, no := range lineStations {
|
||||
parts = append(parts, strconv.Itoa(no))
|
||||
}
|
||||
req.ProcessSeq = strings.Join(parts, ",")
|
||||
} else {
|
||||
req.ProcessSeq = ""
|
||||
}
|
||||
} else {
|
||||
if req.ProcessSeq == "" {
|
||||
req.ProcessSeq = FullProcessSeq
|
||||
} else if err := ValidateProcessSeq(req.ProcessSeq); err != nil {
|
||||
return err
|
||||
}
|
||||
req.ProcessSeq = NormalizeProcessSeq(req.ProcessSeq)
|
||||
}
|
||||
b := s.ctx.EntClient.WorkOrder.Create().
|
||||
SetWorkOrderNo(req.WorkOrderNo).
|
||||
SetProductTypeId(req.ProductTypeId).
|
||||
SetProductCode(req.ProductCode).
|
||||
SetBomName(bomNameOrDefault(req.BomName)).
|
||||
SetProductName(req.ProductName).
|
||||
SetQuantity(req.Quantity).
|
||||
SetProcessSeq(req.ProcessSeq).
|
||||
SetProcessSeq(req.ProcessSeq).SetRouteId(req.RouteId).SetRouteSnapshot(routeSnapshot).
|
||||
SetStatus(status)
|
||||
if req.PlanStart != "" {
|
||||
if t, err := parseDate(req.PlanStart); err == nil {
|
||||
@@ -127,12 +123,6 @@ func (s *Service) UpdateWorkOrder(ctx context.Context, req WorkOrderReq, operato
|
||||
if req.ProductCode != "" {
|
||||
u.SetProductCode(req.ProductCode)
|
||||
}
|
||||
if req.BomName != "" {
|
||||
if err := s.validateBomName(ctx, req.ProductCode, req.BomName); err != nil {
|
||||
return err
|
||||
}
|
||||
u.SetBomName(bomNameOrDefault(req.BomName))
|
||||
}
|
||||
if req.ProductName != "" {
|
||||
u.SetProductName(req.ProductName)
|
||||
}
|
||||
@@ -222,6 +212,17 @@ func (s *Service) SetWorkOrderStatus(ctx context.Context, id int, status, reason
|
||||
if !workOrderTransitions[wo.Status][status] {
|
||||
return fmt.Errorf("不允许从「%s」变更为「%s」", statusTextCN(wo.Status), statusTextCN(status))
|
||||
}
|
||||
// 单工单互斥:一条产线同时只能有一个在产工单(下发/开工前校验)
|
||||
if status == "RELEASED" || status == "IN_PROGRESS" {
|
||||
others, _ := s.ctx.EntClient.WorkOrder.Query().
|
||||
Where(workorder.StatusIn("IN_PROGRESS", "PAUSED")).
|
||||
All(ctx)
|
||||
for _, o := range others {
|
||||
if o.ID != id {
|
||||
return fmt.Errorf("产线上已有在产工单「%s」(%s),完成或暂停后方可下发/开工新工单", o.WorkOrderNo, statusTextCN(o.Status))
|
||||
}
|
||||
}
|
||||
}
|
||||
upd := s.ctx.EntClient.WorkOrder.UpdateOneID(id).SetStatus(status)
|
||||
if status == "DONE" {
|
||||
now := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user