- 移除工位模板体系(handler/logic 全删),同步路由与 seed - AGV 链路增强:点位锁、车辆状态、退料派车调整,新增海康 RCS Postman 调试集合 - MES 产品BOM/混产模板完善:新增 ProductBOMDialog 组件,调整 handler/logic;日排产达成对比调整 - WMS 业务完善:出入库、检验、备料、退料、成品入库、缺料代报等 handler 与前端页面调整 - 前端通用:双端新增 RemotePageSelect 组件,统一 nextStep 规则/帮助文档/布局/请求拦截 - 文档:更新产线API/案例/部署手册/问题记录等
107 lines
3.0 KiB
Go
107 lines
3.0 KiB
Go
package logic
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"sort"
|
||
"strings"
|
||
|
||
"bj_power_mes/ent/dailyplan"
|
||
"bj_power_mes/ent/workorder"
|
||
)
|
||
|
||
// DailyPlanCompareItem 日排产历史对比行(按工单汇集窗口内排产)
|
||
type DailyPlanCompareItem struct {
|
||
WorkOrderNo string `json:"workOrderNo"`
|
||
ProductCode string `json:"productCode"`
|
||
PlanQty int `json:"planQty"`
|
||
CompletedQty int `json:"completedQty"`
|
||
Diff int `json:"diff"`
|
||
PlanDate string `json:"planDate"`
|
||
Status string `json:"status"`
|
||
}
|
||
|
||
// DailyPlanCompareSummary 汇总
|
||
type DailyPlanCompareSummary struct {
|
||
PlanTotal int `json:"planTotal"`
|
||
DoneTotal int `json:"doneTotal"`
|
||
DiffTotal int `json:"diffTotal"`
|
||
OrderCount int `json:"orderCount"`
|
||
}
|
||
|
||
// DailyPlanCompareResult 对比结果
|
||
type DailyPlanCompareResult struct {
|
||
Items []DailyPlanCompareItem `json:"items"`
|
||
Summary DailyPlanCompareSummary `json:"summary"`
|
||
}
|
||
|
||
// DailyPlanCompare 按 [start,end] 查 daily_plan,按工单汇集历史排产:
|
||
// planQty=Σ计划数量、completedQty=Σ已完成、diff=planQty-completedQty;
|
||
// productCode/status 关联 work_order;planDate 取窗口内该工单最早排产日。
|
||
func (s *Service) DailyPlanCompare(ctx context.Context, start, end string) (*DailyPlanCompareResult, error) {
|
||
start = strings.TrimSpace(start)
|
||
end = strings.TrimSpace(end)
|
||
if start == "" || end == "" {
|
||
return nil, errors.New("请指定开始日期与结束日期")
|
||
}
|
||
q := s.ctx.EntClient.DailyPlan.Query().
|
||
Where(dailyplan.PlanDateGTE(start), dailyplan.PlanDateLTE(end))
|
||
plans, err := q.All(ctx)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
// 按工单汇集
|
||
type agg struct {
|
||
planQty int
|
||
doneQty int
|
||
date string
|
||
}
|
||
byOrder := map[string]*agg{}
|
||
for _, p := range plans {
|
||
a := byOrder[p.OrderNo]
|
||
if a == nil {
|
||
a = &agg{}
|
||
byOrder[p.OrderNo] = a
|
||
}
|
||
a.planQty += p.PlanQty
|
||
a.doneQty += p.CompletedQty
|
||
if a.date == "" || p.PlanDate < a.date {
|
||
a.date = p.PlanDate
|
||
}
|
||
}
|
||
orderNos := make([]string, 0, len(byOrder))
|
||
for no := range byOrder {
|
||
orderNos = append(orderNos, no)
|
||
}
|
||
sort.Strings(orderNos)
|
||
// 关联工单:产品编码 + 工单状态
|
||
productCodes := map[string]string{}
|
||
statuses := map[string]string{}
|
||
if len(orderNos) > 0 {
|
||
wos, e := s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNoIn(orderNos...)).All(ctx)
|
||
if e == nil {
|
||
for _, wo := range wos {
|
||
productCodes[wo.WorkOrderNo] = wo.ProductCode
|
||
statuses[wo.WorkOrderNo] = wo.Status
|
||
}
|
||
}
|
||
}
|
||
res := &DailyPlanCompareResult{Items: []DailyPlanCompareItem{}}
|
||
summary := DailyPlanCompareSummary{}
|
||
for _, no := range orderNos {
|
||
a := byOrder[no]
|
||
item := DailyPlanCompareItem{
|
||
WorkOrderNo: no, ProductCode: productCodes[no],
|
||
PlanQty: a.planQty, CompletedQty: a.doneQty, Diff: a.planQty - a.doneQty,
|
||
PlanDate: a.date, Status: statuses[no],
|
||
}
|
||
res.Items = append(res.Items, item)
|
||
summary.PlanTotal += item.PlanQty
|
||
summary.DoneTotal += item.CompletedQty
|
||
}
|
||
summary.DiffTotal = summary.PlanTotal - summary.DoneTotal
|
||
summary.OrderCount = len(res.Items)
|
||
res.Summary = summary
|
||
return res, nil
|
||
}
|