- 移除 bj_power_dashboard 旧 React 大屏源码(迁移至 2D SVG 方案) - MES/WMS/工位终端前端:清理 help.js 与 PageHelp 帮助文档,统一操作列与布局,接入请求拦截器 - 新增收集式校验错误弹窗(ErrorListDialog 统一拦截 3015,逐条列现象+建议) - 新增托盘程序(tray)与 WebSocket(ws) 实时通知模块(三端共用) - MES/WMS 物料档案新增同步状态字段,补齐双向失败重推与默认角色 seed - 工单/产能/产品工艺/日排产逻辑调整;拧紧枪按工位配置 - 新增迁移 SQL:扭矩按工位、sysconfig 序列修复 - 更新 技术约束/案例/部署手册/项目说明 等文档
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
|
||
}
|