feat: 菜单按业务域重排为7组 + 预警中心更名异常告警 + AGV独立权限码与齐套测算分账明细
This commit is contained in:
@@ -10,7 +10,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/dailyplan"
|
||||
"bj_power_mes/ent/flowmaterial"
|
||||
"bj_power_mes/ent/productprocessmaterial"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/internal/wmsclient"
|
||||
)
|
||||
@@ -50,6 +53,7 @@ type ProducibleDailyRow struct {
|
||||
Consumed float64 `json:"consumed"` // 当日消耗(当日该物料需求台数 × 单台含损耗用量)
|
||||
Before float64 `json:"before"` // 当日扣减前可用量
|
||||
Remain float64 `json:"remain"` // 当日扣减后剩余量
|
||||
Source string `json:"source"` // 账目来源:产品工艺分账 / 工序总账(无分账回退)
|
||||
}
|
||||
|
||||
// ProducibleOrderRow 单工单逐日模拟结果(按工单逐个模拟消耗)
|
||||
@@ -61,6 +65,22 @@ type ProducibleOrderRow struct {
|
||||
SupportUntil string `json:"supportUntil"`
|
||||
SupportDays int `json:"supportDays"`
|
||||
DailyRows []ProducibleDailyRow `json:"dailyRows"`
|
||||
UsageBreakdown []ProducibleUsageRow `json:"usageBreakdown"`
|
||||
}
|
||||
|
||||
// ProducibleUsageRow 抽屉里的「物料账目来源」明细:按产品工艺分账逐工序列出的单台用量。
|
||||
// 宏观测算与逐日消耗仍走工序总账口径,本结构只用于展示账目来源,不参与计算。
|
||||
type ProducibleUsageRow struct {
|
||||
Seq int `json:"seq"` // 工单工艺组合中的第几道工序
|
||||
FlowId int `json:"flowId"`
|
||||
FlowName string `json:"flowName"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
UnitQty float64 `json:"unitQty"` // 单台净用量
|
||||
LossRate float64 `json:"lossRate"` // 损耗率%(展示口径,取工序总账)
|
||||
EffQty float64 `json:"effQty"` // 单台含损耗用量
|
||||
Source string `json:"source"` // 产品工艺分账 / 工序总账(无分账回退)
|
||||
}
|
||||
|
||||
// ProducibleBottleneck 总支撑瓶颈:最早见底那个工单
|
||||
@@ -361,9 +381,119 @@ func (s *Service) ComputeProducibleSupport(ctx context.Context) (*ProducibleSupp
|
||||
codeByOrder[it.OrderNo] = it.ProductCode
|
||||
}
|
||||
res.Orders, res.Bottleneck = s.simulateSupportByOrder(ctx, usageByOrder, base.Avail, qtyByOrder, codeByOrder)
|
||||
|
||||
// 逐工单补「物料账目来源」明细:宏观汇总与逐日消耗口径不变(工序总账),
|
||||
// 明细区另按产品工艺分账逐工序展示实际领料量,点进抽屉即可核到账目来源。
|
||||
breakdownByOrder := s.loadUsageBreakdown(ctx, orderNosOf(base.Items))
|
||||
for i := range res.Orders {
|
||||
rows := breakdownByOrder[res.Orders[i].WorkOrderNo]
|
||||
res.Orders[i].UsageBreakdown = rows
|
||||
srcByCode := map[string]string{}
|
||||
for _, r := range rows {
|
||||
if _, has := srcByCode[r.MaterialCode]; !has || r.Source == "产品工艺分账" {
|
||||
srcByCode[r.MaterialCode] = r.Source
|
||||
}
|
||||
}
|
||||
for j := range res.Orders[i].DailyRows {
|
||||
src := srcByCode[res.Orders[i].DailyRows[j].MaterialCode]
|
||||
if src == "" {
|
||||
src = "工序总账"
|
||||
}
|
||||
res.Orders[i].DailyRows[j].Source = src
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// loadUsageBreakdown 批量加载工单的「物料账目来源」明细(工单号 → 分账明细行)。
|
||||
func (s *Service) loadUsageBreakdown(ctx context.Context, orderNos []string) map[string][]ProducibleUsageRow {
|
||||
out := map[string][]ProducibleUsageRow{}
|
||||
if len(orderNos) == 0 {
|
||||
return out
|
||||
}
|
||||
wos, err := s.ctx.EntClient.WorkOrder.Query().
|
||||
Where(workorder.WorkOrderNoIn(orderNos...)).All(ctx)
|
||||
if err != nil {
|
||||
return out
|
||||
}
|
||||
for _, wo := range wos {
|
||||
out[wo.WorkOrderNo] = s.orderUsageBreakdown(ctx, wo)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// orderUsageBreakdown 按产品工艺分账(product_process_material)逐工序列出单台用量:
|
||||
// ① 该工序在分账里有行 → 用分账行的单台净用量,损耗率取工序总账同名物料,来源标「产品工艺分账」;
|
||||
// ② 该工序无分账行 → 回退 flow_material 工序总账,来源标「工序总账(无分账回退)」;
|
||||
// ③ 工单无来源产品工艺 → 全部回退总账。
|
||||
// 与 MaterialsByFlowForWO(叫料/备料/装机绑定的算料口径)同源,仅用于抽屉展示,不参与上方宏观测算。
|
||||
func (s *Service) orderUsageBreakdown(ctx context.Context, wo *ent.WorkOrder) []ProducibleUsageRow {
|
||||
if wo == nil || s.ctx.EntClient == nil {
|
||||
return []ProducibleUsageRow{}
|
||||
}
|
||||
items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo)
|
||||
seen := map[int]bool{}
|
||||
flowIDs := make([]int, 0, len(items))
|
||||
for _, it := range items {
|
||||
if it.FlowId > 0 && !seen[it.FlowId] {
|
||||
seen[it.FlowId] = true
|
||||
flowIDs = append(flowIDs, it.FlowId)
|
||||
}
|
||||
}
|
||||
if len(flowIDs) == 0 {
|
||||
return []ProducibleUsageRow{}
|
||||
}
|
||||
flowName := map[int]string{}
|
||||
for _, fid := range flowIDs {
|
||||
if f, err := s.ctx.EntClient.ProcessFlow.Get(ctx, fid); err == nil {
|
||||
flowName[fid] = f.Name
|
||||
}
|
||||
}
|
||||
allocByFlow := map[int][]*ent.ProductProcessMaterial{}
|
||||
if wo.ProductProcessId > 0 {
|
||||
if rows, err := s.ctx.EntClient.ProductProcessMaterial.Query().
|
||||
Where(productprocessmaterial.ProductProcessId(wo.ProductProcessId)).All(ctx); err == nil {
|
||||
for _, r := range rows {
|
||||
allocByFlow[r.FlowId] = append(allocByFlow[r.FlowId], r)
|
||||
}
|
||||
}
|
||||
}
|
||||
fms, _ := s.ctx.EntClient.FlowMaterial.Query().
|
||||
Where(flowmaterial.FlowIdIn(flowIDs...)).All(ctx)
|
||||
lossByCode := map[string]float64{}
|
||||
fmByFlow := map[int][]*ent.FlowMaterial{}
|
||||
for _, fm := range fms {
|
||||
lossByCode[fm.MaterialCode] = fm.LossRate
|
||||
fmByFlow[fm.FlowId] = append(fmByFlow[fm.FlowId], fm)
|
||||
}
|
||||
out := make([]ProducibleUsageRow, 0, len(fms))
|
||||
for seq, fid := range flowIDs {
|
||||
rows := allocByFlow[fid]
|
||||
if len(rows) > 0 {
|
||||
sort.SliceStable(rows, func(i, j int) bool { return rows[i].Seq < rows[j].Seq })
|
||||
for _, r := range rows {
|
||||
loss := lossByCode[r.MaterialCode]
|
||||
out = append(out, ProducibleUsageRow{
|
||||
Seq: seq + 1, FlowId: fid, FlowName: flowName[fid],
|
||||
MaterialCode: r.MaterialCode, MaterialName: r.MaterialName, Unit: r.Unit,
|
||||
UnitQty: r.UnitQty, LossRate: loss,
|
||||
EffQty: r.UnitQty * (1 + loss/100), Source: "产品工艺分账",
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
for _, fm := range fmByFlow[fid] {
|
||||
out = append(out, ProducibleUsageRow{
|
||||
Seq: seq + 1, FlowId: fid, FlowName: flowName[fid],
|
||||
MaterialCode: fm.MaterialCode, MaterialName: fm.MaterialName, Unit: fm.Unit,
|
||||
UnitQty: fm.UnitQty, LossRate: fm.LossRate,
|
||||
EffQty: fm.UnitQty * (1 + fm.LossRate/100), Source: "工序总账(无分账回退)",
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// orderNosOf 从可生产结果提取工单号(保持顺序)
|
||||
func orderNosOf(items []wmsclient.ProducibleItem) []string {
|
||||
out := make([]string, 0, len(items))
|
||||
|
||||
Reference in New Issue
Block a user