feat: 新增工序签字功能,移除移料指令模块
新增操作工/检验员工序签字功能,支持工艺步骤配置签字要求;删除移料指令相关代码,将移料页签重命名为产线点位(上料/下料);新增成品入库功能及相关权限;优化备料单状态、质量状态逻辑,新增批次序号字段;修复AGV取消后备料单回退状态问题。
This commit is contained in:
@@ -3,7 +3,6 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -12,7 +11,6 @@ import (
|
||||
"bj_power_mes/ent/processstep"
|
||||
"bj_power_mes/ent/station"
|
||||
"bj_power_mes/ent/stepcriterion"
|
||||
"bj_power_mes/ent/torqueauditlog"
|
||||
"bj_power_mes/ent/torquerecord"
|
||||
"bj_power_mes/ent/workpiece"
|
||||
)
|
||||
@@ -156,263 +154,6 @@ func (s *Service) ListTorqueRecords(ctx context.Context, sn, workOrderNo, statio
|
||||
return q.Order(ent.Desc(torquerecord.FieldTime)).Limit(500).All(ctx)
|
||||
}
|
||||
|
||||
// requiredScrews 按工位号取该工位绑定工艺流程中 isTorque=true 的步骤数 = 应拧数量。
|
||||
// 工位未绑定流程或流程无扭矩步骤时返回 0(表示无工艺基准,前端标注为「未配置」)。
|
||||
func (s *Service) requiredScrews(ctx context.Context, stationNo string) int {
|
||||
flowId := s.stationFlowId(ctx, stationNo)
|
||||
if flowId <= 0 {
|
||||
return 0
|
||||
}
|
||||
cnt, _ := s.ctx.EntClient.ProcessStep.Query().
|
||||
Where(processstep.FlowId(flowId), processstep.IsTorque(true)).Count(ctx)
|
||||
return cnt
|
||||
}
|
||||
|
||||
// TorqueGroupVO 拧紧一级汇总行(按 工单号+SN+工位 分组)
|
||||
type TorqueGroupVO struct {
|
||||
WorkOrderNo string `json:"workOrderNo"`
|
||||
Sn string `json:"sn"`
|
||||
StationNo string `json:"stationNo"`
|
||||
Required int `json:"required"` // 应拧数量(工艺流程 isTorque 步骤数)
|
||||
Actual int `json:"actual"` // 实际记录数
|
||||
OkCount int `json:"okCount"` // 合格颗数
|
||||
NgCount int `json:"ngCount"` // 不合格颗数
|
||||
Satisfied bool `json:"satisfied"` // 是否满足:应拧>0 且 实拧>=应拧 且 无不合格
|
||||
Audited bool `json:"audited"` // 是否已全部审核签字
|
||||
Operator string `json:"operator"` // 最近操作人
|
||||
LastTime time.Time `json:"lastTime"` // 最近采集时间
|
||||
}
|
||||
|
||||
// ListTorqueGroups 拧紧一级汇总列表:按 工单号+SN+工位 分组,附「应拧 vs 实拧」满足判定,后端真分页。
|
||||
func (s *Service) ListTorqueGroups(ctx context.Context, sn, workOrderNo, stationNo string, from, to time.Time, page, pageSize int) (map[string]any, error) {
|
||||
recs, err := s.ListTorqueRecords(ctx, sn, workOrderNo, stationNo, from, to)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type gkey struct{ wo, sn, st string }
|
||||
agg := map[gkey]*TorqueGroupVO{}
|
||||
reqCache := map[string]int{}
|
||||
for _, r := range recs {
|
||||
k := gkey{r.WorkOrderNo, r.Sn, r.StationNo}
|
||||
g, ok := agg[k]
|
||||
if !ok {
|
||||
g = &TorqueGroupVO{WorkOrderNo: r.WorkOrderNo, Sn: r.Sn, StationNo: r.StationNo}
|
||||
agg[k] = g
|
||||
}
|
||||
g.Actual++
|
||||
if r.Result == "OK" {
|
||||
g.OkCount++
|
||||
} else {
|
||||
g.NgCount++
|
||||
}
|
||||
if r.Time.After(g.LastTime) {
|
||||
g.LastTime = r.Time
|
||||
g.Operator = r.Operator
|
||||
}
|
||||
}
|
||||
list := make([]*TorqueGroupVO, 0, len(agg))
|
||||
for _, g := range agg {
|
||||
req, ok := reqCache[g.StationNo]
|
||||
if !ok {
|
||||
req = s.requiredScrews(ctx, g.StationNo)
|
||||
reqCache[g.StationNo] = req
|
||||
}
|
||||
g.Required = req
|
||||
g.Satisfied = req > 0 && g.Actual >= req && g.NgCount == 0
|
||||
list = append(list, g)
|
||||
}
|
||||
// Audited 需基于分组内全部记录:任一条未审核即整组未审核
|
||||
auditOK := map[gkey]bool{}
|
||||
for _, r := range recs {
|
||||
k := gkey{r.WorkOrderNo, r.Sn, r.StationNo}
|
||||
if _, seen := auditOK[k]; !seen {
|
||||
auditOK[k] = true
|
||||
}
|
||||
if r.AuditBy == "" {
|
||||
auditOK[k] = false
|
||||
}
|
||||
}
|
||||
for _, g := range list {
|
||||
g.Audited = auditOK[gkey{g.WorkOrderNo, g.Sn, g.StationNo}]
|
||||
}
|
||||
sort.Slice(list, func(i, j int) bool { return list[i].LastTime.After(list[j].LastTime) })
|
||||
|
||||
total := len(list)
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
start := (page - 1) * pageSize
|
||||
if start > total {
|
||||
start = total
|
||||
}
|
||||
end := start + pageSize
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
return map[string]any{"total": total, "list": list[start:end], "page": page, "pageSize": pageSize}, nil
|
||||
}
|
||||
|
||||
// TorqueScrewStat 单工件单工位「应拧 vs 实拧」统计(二级明细抽屉顶部展示)
|
||||
func (s *Service) TorqueScrewStat(ctx context.Context, sn, stationNo string) (*TorqueGroupVO, error) {
|
||||
if strings.TrimSpace(sn) == "" {
|
||||
return nil, errors.New("sn 不能为空")
|
||||
}
|
||||
q := s.ctx.EntClient.TorqueRecord.Query().Where(torquerecord.SnEqualFold(sn))
|
||||
if stationNo != "" {
|
||||
q = q.Where(torquerecord.StationNoEqualFold(stationNo))
|
||||
}
|
||||
recs, _ := q.All(ctx)
|
||||
vo := &TorqueGroupVO{Sn: sn, StationNo: stationNo, Required: s.requiredScrews(ctx, stationNo)}
|
||||
allAudited := len(recs) > 0
|
||||
for _, r := range recs {
|
||||
vo.Actual++
|
||||
if r.WorkOrderNo != "" && vo.WorkOrderNo == "" {
|
||||
vo.WorkOrderNo = r.WorkOrderNo
|
||||
}
|
||||
if r.Result == "OK" {
|
||||
vo.OkCount++
|
||||
} else {
|
||||
vo.NgCount++
|
||||
}
|
||||
if r.AuditBy == "" {
|
||||
allAudited = false
|
||||
}
|
||||
if r.Time.After(vo.LastTime) {
|
||||
vo.LastTime = r.Time
|
||||
vo.Operator = r.Operator
|
||||
}
|
||||
}
|
||||
vo.Satisfied = vo.Required > 0 && vo.Actual >= vo.Required && vo.NgCount == 0
|
||||
vo.Audited = allAudited
|
||||
return vo, nil
|
||||
}
|
||||
|
||||
// AuditTorqueRecord 拧紧记录审核签字:标记审核人/时间并写留痕
|
||||
func (s *Service) AuditTorqueRecord(ctx context.Context, recordId int, remark, operator string) error {
|
||||
rec, err := s.ctx.EntClient.TorqueRecord.Get(ctx, recordId)
|
||||
if err != nil {
|
||||
return errors.New("拧紧记录不存在")
|
||||
}
|
||||
if rec.AuditBy != "" {
|
||||
return errors.New("该记录已审核,不可重复审核")
|
||||
}
|
||||
_, err = rec.Update().SetAuditBy(operator).SetAuditAt(time.Now()).Save(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, _ = s.ctx.EntClient.TorqueAuditLog.Create().
|
||||
SetTorqueRecordId(rec.ID).SetAction("审核").SetOperator(operator).
|
||||
SetRemark(remark).SetOldVal(rec.AuditBy).SetNewVal(operator).Save(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListTorqueAuditLog 查询某拧紧记录的修改留痕
|
||||
func (s *Service) ListTorqueAuditLog(ctx context.Context, recordId int) ([]*ent.TorqueAuditLog, error) {
|
||||
return s.ctx.EntClient.TorqueAuditLog.Query().
|
||||
Where(torqueauditlog.TorqueRecordId(recordId)).
|
||||
Order(ent.Desc(torqueauditlog.FieldCreatedAt)).All(ctx)
|
||||
}
|
||||
|
||||
// ListTorquePendingGroups 巡检终端「待签任务」:聚合 AuditBy==""(未审核)的拧紧记录,
|
||||
// 按 工单号+SN+工位 分组(口径同 ListTorqueGroups),供检验员集中第二签。
|
||||
// Actual/OkCount/NgCount 只统计未审核子集,LastTime/Operator 取子集中最近采集记录;
|
||||
// 按 LastTime 倒序,后端真分页,返回 {"total","list","page","pageSize"}。
|
||||
func (s *Service) ListTorquePendingGroups(ctx context.Context, page, pageSize int) (map[string]any, error) {
|
||||
recs, err := s.ctx.EntClient.TorqueRecord.Query().
|
||||
Where(torquerecord.AuditByEqualFold("")).
|
||||
Order(ent.Desc(torquerecord.FieldTime)).
|
||||
All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type gkey struct{ wo, sn, st string }
|
||||
agg := map[gkey]*TorqueGroupVO{}
|
||||
reqCache := map[string]int{}
|
||||
for _, r := range recs {
|
||||
k := gkey{r.WorkOrderNo, r.Sn, r.StationNo}
|
||||
g, ok := agg[k]
|
||||
if !ok {
|
||||
g = &TorqueGroupVO{WorkOrderNo: r.WorkOrderNo, Sn: r.Sn, StationNo: r.StationNo}
|
||||
agg[k] = g
|
||||
}
|
||||
g.Actual++
|
||||
if r.Result == "OK" {
|
||||
g.OkCount++
|
||||
} else {
|
||||
g.NgCount++
|
||||
}
|
||||
if r.Time.After(g.LastTime) {
|
||||
g.LastTime = r.Time
|
||||
g.Operator = r.Operator
|
||||
}
|
||||
}
|
||||
list := make([]*TorqueGroupVO, 0, len(agg))
|
||||
for _, g := range agg {
|
||||
req, ok := reqCache[g.StationNo]
|
||||
if !ok {
|
||||
req = s.requiredScrews(ctx, g.StationNo)
|
||||
reqCache[g.StationNo] = req
|
||||
}
|
||||
g.Required = req
|
||||
g.Satisfied = req > 0 && g.Actual >= req && g.NgCount == 0
|
||||
g.Audited = false // 待签列表只含未审核记录,整组必然未审核
|
||||
list = append(list, g)
|
||||
}
|
||||
sort.Slice(list, func(i, j int) bool { return list[i].LastTime.After(list[j].LastTime) })
|
||||
|
||||
total := len(list)
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
start := (page - 1) * pageSize
|
||||
if start > total {
|
||||
start = total
|
||||
}
|
||||
end := start + pageSize
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
return map[string]any{"total": total, "list": list[start:end], "page": page, "pageSize": pageSize}, nil
|
||||
}
|
||||
|
||||
// AuditTorqueGroup 拧紧分组批量审核签字(巡检终端「待签任务」):把该组(工单号+SN+工位)
|
||||
// 全部未审核记录一次性标记审核人/时间,并逐条写 TorqueAuditLog 留痕,返回签字条数。
|
||||
// 组内没有未审核记录时返回明确错误,避免前端对已签字任务重复提交静默成功。
|
||||
func (s *Service) AuditTorqueGroup(ctx context.Context, workOrderNo, sn, stationNo, remark, operator string) (int, error) {
|
||||
if strings.TrimSpace(sn) == "" {
|
||||
return 0, errors.New("sn 不能为空")
|
||||
}
|
||||
recs, err := s.ctx.EntClient.TorqueRecord.Query().
|
||||
Where(
|
||||
torquerecord.WorkOrderNoEqualFold(workOrderNo),
|
||||
torquerecord.SnEqualFold(sn),
|
||||
torquerecord.StationNoEqualFold(stationNo),
|
||||
torquerecord.AuditByEqualFold(""),
|
||||
).All(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(recs) == 0 {
|
||||
return 0, errors.New("该任务没有待审核的拧紧记录,可能已签字")
|
||||
}
|
||||
now := time.Now()
|
||||
for _, rec := range recs {
|
||||
if _, err := rec.Update().SetAuditBy(operator).SetAuditAt(now).Save(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
_, _ = s.ctx.EntClient.TorqueAuditLog.Create().
|
||||
SetTorqueRecordId(rec.ID).SetAction("审核").SetOperator(operator).
|
||||
SetRemark(remark).SetOldVal(rec.AuditBy).SetNewVal(operator).Save(ctx)
|
||||
}
|
||||
return len(recs), nil
|
||||
}
|
||||
|
||||
// ProcessStepTemplate 下发给前端渲染的参数采集模板
|
||||
type ProcessStepTemplate struct {
|
||||
ID int `json:"id"`
|
||||
@@ -421,6 +162,9 @@ type ProcessStepTemplate struct {
|
||||
CollectType string `json:"collectType"` // AUTO(拧紧枪自动)/MANUAL(手填)/NONE
|
||||
IsTorque bool `json:"isTorque"`
|
||||
NeedCheck bool `json:"needCheck"`
|
||||
// 签字机制(需求B):操作工报工前须签字确认 / 检验员待签任务须签字确认方可流转
|
||||
NeedOperatorSign bool `json:"needOperatorSign"`
|
||||
NeedInspectorSign bool `json:"needInspectorSign"`
|
||||
Remark string `json:"remark"`
|
||||
Attachment []map[string]string `json:"attachment"` // 本步骤图纸/附件 [{name,url}],按工序分发到工位终端
|
||||
Criteria []CriterionVO `json:"criteria"`
|
||||
@@ -464,6 +208,9 @@ type StepItemReq struct {
|
||||
CollectType string `json:"collectType"`
|
||||
IsTorque bool `json:"isTorque"`
|
||||
NeedCheck bool `json:"needCheck"`
|
||||
// 签字机制(需求B):保存工艺步骤时携带,落库到 process_step 表
|
||||
NeedOperatorSign bool `json:"needOperatorSign"`
|
||||
NeedInspectorSign bool `json:"needInspectorSign"`
|
||||
Remark string `json:"remark"`
|
||||
Attachment []map[string]string `json:"attachment"` // 本步骤图纸/附件 [{name,url}]
|
||||
Criteria []CriterionVO `json:"criteria"`
|
||||
|
||||
Reference in New Issue
Block a user