feat: 新增工序签字功能,移除移料指令模块
新增操作工/检验员工序签字功能,支持工艺步骤配置签字要求;删除移料指令相关代码,将移料页签重命名为产线点位(上料/下料);新增成品入库功能及相关权限;优化备料单状态、质量状态逻辑,新增批次序号字段;修复AGV取消后备料单回退状态问题。
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/stepsignrecord"
|
||||
)
|
||||
|
||||
// StepSignVO 签字记录视图对象,返回给前端(巡检终端「待签任务」/追溯展示)。
|
||||
type StepSignVO struct {
|
||||
ID int `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
FlowId int `json:"flowId"`
|
||||
StationNo string `json:"stationNo"`
|
||||
StepId int `json:"stepId"`
|
||||
StepName string `json:"stepName"`
|
||||
SignRole string `json:"signRole"`
|
||||
Result string `json:"result"`
|
||||
SignedBy string `json:"signedBy"`
|
||||
SignedAt string `json:"signedAt"`
|
||||
Round int `json:"round"`
|
||||
Source string `json:"source"`
|
||||
Revoked bool `json:"revoked"`
|
||||
OperatorSigner string `json:"operatorSigner"` // 操作工签字人(只读展示)
|
||||
OperatorSignedAt string `json:"operatorSignedAt"` // 操作工签字时间
|
||||
HasInspectorSign bool `json:"hasInspectorSign"` // 是否已有检验员 OK 签字
|
||||
}
|
||||
|
||||
// InspectorSignReq 检验员签字确认请求(需求B:第二签)。
|
||||
type InspectorSignReq struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo string `json:"stationNo"`
|
||||
StepId int `json:"stepId"`
|
||||
Result string `json:"result"` // OK / NG
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
// InspectorSign 落检验员签字(signRole=INSPECTOR);轮次=该(sn,stationNo,stepId)已签字最大轮次+1。
|
||||
// 前置:步骤须 needInspectorSign=true,且操作工已签字(OPERATOR,未撤销,有签字人)——双签顺序先 OPERATOR 后 INSPECTOR。
|
||||
// result=NG 表示检验不合格,不通过流转(报工门禁 validateNeedSign 仅认 OK)。
|
||||
func (s *Service) InspectorSign(ctx context.Context, req InspectorSignReq, operator string) error {
|
||||
req.Sn = strings.TrimSpace(req.Sn)
|
||||
req.StationNo = strings.TrimSpace(req.StationNo)
|
||||
req.OrderNo = strings.TrimSpace(req.OrderNo)
|
||||
if req.Sn == "" || req.StationNo == "" || req.StepId <= 0 {
|
||||
return errors.New("签字参数不完整:缺少 SN / 工位号 / 步骤")
|
||||
}
|
||||
if operator == "" {
|
||||
return errors.New("未获取到检验员身份,请重新登录")
|
||||
}
|
||||
client := s.ctx.EntClient
|
||||
ps, err := client.ProcessStep.Get(ctx, req.StepId)
|
||||
if err != nil {
|
||||
return errors.New("工艺步骤不存在:" + itoa(req.StepId))
|
||||
}
|
||||
if !ps.NeedInspectorSign {
|
||||
return errors.New("该步骤未配置「需检验员签字」,无需签字确认")
|
||||
}
|
||||
// 操作工必须先签字(双签顺序约束)
|
||||
opSigned, e := client.StepSignRecord.Query().
|
||||
Where(stepsignrecord.Sn(req.Sn), stepsignrecord.StationNo(req.StationNo),
|
||||
stepsignrecord.StepId(req.StepId), stepsignrecord.SignRole("OPERATOR"),
|
||||
stepsignrecord.Revoked(false), stepsignrecord.SignedByNEQ("")).Exist(ctx)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if !opSigned {
|
||||
return errors.New("操作工尚未签字,检验员不能先于操作工签字")
|
||||
}
|
||||
// 计算轮次(返修重做每轮签字递增)
|
||||
recs, e := client.StepSignRecord.Query().
|
||||
Where(stepsignrecord.Sn(req.Sn), stepsignrecord.StationNo(req.StationNo),
|
||||
stepsignrecord.StepId(req.StepId), stepsignrecord.SignRole("INSPECTOR")).All(ctx)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
round := 1
|
||||
for _, r := range recs {
|
||||
if r.Round >= round {
|
||||
round = r.Round + 1
|
||||
}
|
||||
}
|
||||
result := strings.ToUpper(strings.TrimSpace(req.Result))
|
||||
if result != "OK" && result != "NG" {
|
||||
result = "OK"
|
||||
}
|
||||
_, err = client.StepSignRecord.Create().
|
||||
SetSn(req.Sn).SetOrderNo(req.OrderNo).SetFlowId(ps.FlowId).
|
||||
SetStationNo(req.StationNo).SetStepId(req.StepId).SetStepName(ps.Name).
|
||||
SetSignRole("INSPECTOR").SetResult(result).
|
||||
SetSignedBy(operator).SetRound(round).
|
||||
SetSource("inspect").SetRemark(req.Remark).Save(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PendingSignFilter 待检验员签字查询过滤。
|
||||
type PendingSignFilter struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo string `json:"stationNo"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
// PendingSigns 聚合「操作工已签字、待检验员签字确认」的工艺步骤(需求B 巡检终端「待签任务」数据源)。
|
||||
// 基数=操作工已签字(未撤销)的步骤;剔除其中已有检验员 OK 签字(未撤销)的步骤,剩余即待签。
|
||||
func (s *Service) PendingSigns(ctx context.Context, f PendingSignFilter) ([]StepSignVO, int, error) {
|
||||
client := s.ctx.EntClient
|
||||
q := client.StepSignRecord.Query().
|
||||
Where(stepsignrecord.SignRole("OPERATOR"), stepsignrecord.Revoked(false), stepsignrecord.SignedByNEQ(""))
|
||||
if f.Sn != "" {
|
||||
q = q.Where(stepsignrecord.Sn(f.Sn))
|
||||
}
|
||||
if f.OrderNo != "" {
|
||||
q = q.Where(stepsignrecord.OrderNo(f.OrderNo))
|
||||
}
|
||||
if f.StationNo != "" {
|
||||
q = q.Where(stepsignrecord.StationNo(f.StationNo))
|
||||
}
|
||||
ops, err := q.Order(ent.Desc(stepsignrecord.FieldID)).All(ctx)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
// 标记哪些 (sn,stationNo,stepId) 已有检验员 OK 签字
|
||||
type signKey struct {
|
||||
sn, stationNo string
|
||||
stepId int
|
||||
}
|
||||
inspectorOK := map[signKey]bool{}
|
||||
insp, e := client.StepSignRecord.Query().
|
||||
Where(stepsignrecord.SignRole("INSPECTOR"), stepsignrecord.Revoked(false),
|
||||
stepsignrecord.Result("OK"), stepsignrecord.SignedByNEQ("")).All(ctx)
|
||||
if e != nil {
|
||||
return nil, 0, e
|
||||
}
|
||||
for _, r := range insp {
|
||||
inspectorOK[signKey{r.Sn, r.StationNo, r.StepId}] = true
|
||||
}
|
||||
list := make([]StepSignVO, 0, len(ops))
|
||||
for _, r := range ops {
|
||||
if inspectorOK[signKey{r.Sn, r.StationNo, r.StepId}] {
|
||||
continue
|
||||
}
|
||||
signedAt := r.SignedAt.Format("2006-01-02 15:04:05")
|
||||
list = append(list, StepSignVO{
|
||||
ID: r.ID,
|
||||
Sn: r.Sn,
|
||||
OrderNo: r.OrderNo,
|
||||
FlowId: r.FlowId,
|
||||
StationNo: r.StationNo,
|
||||
StepId: r.StepId,
|
||||
StepName: r.StepName,
|
||||
SignRole: r.SignRole,
|
||||
Result: r.Result,
|
||||
SignedBy: r.SignedBy,
|
||||
SignedAt: signedAt,
|
||||
Round: r.Round,
|
||||
Source: r.Source,
|
||||
OperatorSigner: r.SignedBy,
|
||||
OperatorSignedAt: signedAt,
|
||||
HasInspectorSign: false,
|
||||
})
|
||||
}
|
||||
total := len(list)
|
||||
// 内存分页(基数为已签字步骤,量级小;非全表假分页)
|
||||
ps := f.PageSize
|
||||
if ps <= 0 {
|
||||
ps = 50
|
||||
}
|
||||
pg := f.Page
|
||||
if pg <= 0 {
|
||||
pg = 1
|
||||
}
|
||||
start := (pg - 1) * ps
|
||||
if start >= total {
|
||||
return []StepSignVO{}, total, nil
|
||||
}
|
||||
end := start + ps
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
return list[start:end], total, nil
|
||||
}
|
||||
Reference in New Issue
Block a user