2026-09-04 14:18:53 +08:00
|
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
看板前端契约层(bj_power_dashboard/src/types.ts)
|
|
|
|
|
|
|
|
|
|
|
|
MES 内部保留一套“富”聚合(DashboardSnapshot:质量/报警/绩效/AGV 等,供后续扩展),
|
|
|
|
|
|
而看板对外只暴露甲方约定的正面指标(见 types.ts 注释):
|
|
|
|
|
|
- 不直接下发合格率/不良/报警等负面字段
|
|
|
|
|
|
- 当前订单卡片:合同 / 负责人 / 工期 / 完成度 / 可追溯
|
|
|
|
|
|
- 设备一律以“在线台数”等正面口径
|
|
|
|
|
|
|
|
|
|
|
|
此文件把富快照映射为前端 JSON,字段名与 types.ts 一一对应。
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// FrontToolState 单把工具(扫码枪 / 拧紧枪)
|
|
|
|
|
|
type FrontToolState struct {
|
|
|
|
|
|
Status string `json:"status"` // online / offline / busy / alarm
|
|
|
|
|
|
CurrentSn string `json:"currentSn,omitempty"`
|
|
|
|
|
|
ProcessedCount int `json:"processedCount"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FrontStation 工位(前端 Station)
|
|
|
|
|
|
type FrontStation struct {
|
|
|
|
|
|
ID int `json:"id"`
|
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
|
Status string `json:"status"` // running / idle / alarm / offline
|
|
|
|
|
|
ScanGun FrontToolState `json:"scanGun"`
|
|
|
|
|
|
TighteningGun FrontToolState `json:"tighteningGun"`
|
|
|
|
|
|
CurrentSn string `json:"currentSn"`
|
|
|
|
|
|
CurrentOperator string `json:"currentOperator"`
|
2026-10-28 10:10:17 +08:00
|
|
|
|
CurrentProcess string `json:"currentProcess"` // 最近一道工序名
|
|
|
|
|
|
DoneCount int `json:"doneCount"` // 今日完成数
|
|
|
|
|
|
Paused bool `json:"paused"` // 当天已停单(前端仅图标提示)
|
|
|
|
|
|
PauseReason string `json:"pauseReason,omitempty"`
|
2026-09-04 14:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FrontProduction 产能总览(前端 ProductionOverview)
|
|
|
|
|
|
type FrontProduction struct {
|
|
|
|
|
|
OutputToday int `json:"outputToday"`
|
|
|
|
|
|
TargetToday int `json:"targetToday"`
|
|
|
|
|
|
PassCount int `json:"passCount"` // 一次通过件数(替代合格率)
|
|
|
|
|
|
TorqueCount int `json:"torqueCount"`
|
|
|
|
|
|
InLine int `json:"inLine"`
|
|
|
|
|
|
DeviceOnline int `json:"deviceOnline"`
|
|
|
|
|
|
DeviceTotal int `json:"deviceTotal"`
|
2026-10-20 16:36:26 +08:00
|
|
|
|
CycleTimeMin float64 `json:"cycleTime"` // 实际生产节拍(分钟)
|
2026-09-04 14:18:53 +08:00
|
|
|
|
StationSummary StationSummary `json:"stationSummary"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FrontMovement 出入库动态(实时事件流)
|
|
|
|
|
|
type FrontMovement struct {
|
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
|
Time string `json:"time"`
|
|
|
|
|
|
Type string `json:"type"` // in / out
|
|
|
|
|
|
Material string `json:"material"`
|
|
|
|
|
|
Qty int `json:"qty"`
|
|
|
|
|
|
Operator string `json:"operator"`
|
2026-10-20 16:36:26 +08:00
|
|
|
|
Batch string `json:"batch"` // 批次号
|
2026-09-04 14:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FrontWarehouse 仓储动态(前端 WarehouseOverview,数据源 WMS 8890)
|
|
|
|
|
|
type FrontWarehouse struct {
|
2026-10-20 16:36:26 +08:00
|
|
|
|
TotalStock int `json:"totalStock"`
|
|
|
|
|
|
MaterialTypes int `json:"materialTypes"`
|
|
|
|
|
|
InboundToday int `json:"inboundToday"`
|
|
|
|
|
|
OutboundToday int `json:"outboundToday"`
|
|
|
|
|
|
LocationUsed int `json:"locationUsed"`
|
|
|
|
|
|
LocationTotal int `json:"locationTotal"`
|
|
|
|
|
|
PendingInbound int `json:"pendingInbound"`
|
|
|
|
|
|
PendingOutbound int `json:"pendingOutbound"`
|
|
|
|
|
|
Movements []FrontMovement `json:"movements"`
|
2026-09-04 14:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FrontProgress 当前订单卡片(前端 ProductionProgress)
|
|
|
|
|
|
type FrontProgress struct {
|
|
|
|
|
|
OrderNo string `json:"orderNo"`
|
|
|
|
|
|
ContractNo string `json:"contractNo"`
|
|
|
|
|
|
ProductName string `json:"productName"`
|
|
|
|
|
|
Owner string `json:"owner"`
|
|
|
|
|
|
PlanStart string `json:"planStart"`
|
|
|
|
|
|
PlanEnd string `json:"planEnd"`
|
|
|
|
|
|
RemainDays int `json:"remainDays"`
|
|
|
|
|
|
TotalQty int `json:"totalQty"`
|
|
|
|
|
|
DoneQty int `json:"doneQty"`
|
|
|
|
|
|
Progress float64 `json:"progress"`
|
|
|
|
|
|
ProcessDone int `json:"processDone"`
|
|
|
|
|
|
ProcessTotal int `json:"processTotal"`
|
|
|
|
|
|
CurrentProcess string `json:"currentProcess"`
|
|
|
|
|
|
Status string `json:"status"`
|
|
|
|
|
|
TraceStepCount int `json:"traceStepCount"`
|
|
|
|
|
|
Traceable bool `json:"traceable"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FrontTrends 近 7 日产量趋势(前端 TrendData:{ production: [...] })
|
|
|
|
|
|
type FrontTrends struct {
|
|
|
|
|
|
Production []TrendPoint `json:"production"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FrontDashboard 前端全量快照(与 types.ts DashboardData 对齐;isDemo 由前端标注,不回传)
|
|
|
|
|
|
type FrontDashboard struct {
|
|
|
|
|
|
UpdatedAt string `json:"updatedAt"`
|
|
|
|
|
|
Production FrontProduction `json:"production"`
|
|
|
|
|
|
Warehouse FrontWarehouse `json:"warehouse"`
|
|
|
|
|
|
Equipment []FrontStation `json:"equipment"`
|
2026-10-29 18:16:53 +08:00
|
|
|
|
// VirtualStations 虚拟工位(OFFLINE,不连PLC):地图"虚拟工位"滚动栏展示,不混入 equipment(12 工位映射口径不变)
|
|
|
|
|
|
VirtualStations []FrontStation `json:"virtualStations"`
|
2026-09-04 14:18:53 +08:00
|
|
|
|
Progress FrontProgress `json:"progress"`
|
2026-10-29 18:16:53 +08:00
|
|
|
|
// ProgressList 当前在产订单列表(多订单轮播):进行中的工单排前,最多 6 条;
|
|
|
|
|
|
// 首条与 Progress 一致(老消费方可继续只用 progress)。
|
|
|
|
|
|
ProgressList []FrontProgress `json:"progressList"`
|
2026-09-04 14:18:53 +08:00
|
|
|
|
Traces []TraceItem `json:"traces"`
|
|
|
|
|
|
Trends FrontTrends `json:"trends"`
|
2026-10-28 10:10:17 +08:00
|
|
|
|
// Points 产线点位态(主线 15 位 / 接驳台 21 位 / 在途路径指令),驱动 2D 地图真实亮灭与流光
|
|
|
|
|
|
Points FrontPoints `json:"points"`
|
|
|
|
|
|
// Agv AGV 实时搬运任务(真实备料任务驱动;无坐标,前端按状态+目标接驳台做过渡动画)
|
|
|
|
|
|
Agv []FrontAgvRobot `json:"agv"`
|
|
|
|
|
|
// Events 实时事件流(已过滤 NG 结果项:大屏报喜不报忧,负面事件只走语音播报)
|
|
|
|
|
|
Events []EventItem `json:"events"`
|
2026-10-20 16:36:26 +08:00
|
|
|
|
// Alarms 仅用于前端语音播报(D2),不渲染到屏幕(报喜不报忧)。
|
|
|
|
|
|
Alarms []AlarmItem `json:"alarms"`
|
2026-10-26 16:32:35 +08:00
|
|
|
|
// RefreshSeconds 看板轮询兜底刷新间隔(秒,1~10),由 dashboard.refresh.seconds 配置驱动;
|
|
|
|
|
|
// 仅影响 SSE 实时通道不可用时的 HTTP 轮询周期,SSE 可用时不依赖此值。
|
|
|
|
|
|
RefreshSeconds int `json:"refreshSeconds"`
|
2026-09-04 14:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DashboardFrontSnapshot 看板前端快照:富聚合 → 前端契约映射,走同一缓存(60s + 防击穿)。
|
|
|
|
|
|
func (s *Service) DashboardFrontSnapshot(ctx context.Context) (*FrontDashboard, error) {
|
|
|
|
|
|
return cachedTyped(ctx, s, "dashboard:front", dashboardTTL, func() (*FrontDashboard, error) {
|
|
|
|
|
|
rich, err := s.DashboardSnapshot(ctx)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2026-10-28 10:10:17 +08:00
|
|
|
|
f := s.mapFrontDashboard(ctx, rich)
|
2026-10-26 16:32:35 +08:00
|
|
|
|
f.RefreshSeconds = s.CfgInt(ctx, CfgDashboardRefreshSeconds, 5)
|
|
|
|
|
|
return f, nil
|
2026-09-04 14:18:53 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// mapFrontDashboard 富快照 → 前端契约。
|
|
|
|
|
|
// 展示口径按甲方要求:负面字段(合格率/不良数/报警)一律不出现。
|
2026-10-28 10:10:17 +08:00
|
|
|
|
func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *FrontDashboard {
|
2026-09-04 14:18:53 +08:00
|
|
|
|
f := &FrontDashboard{UpdatedAt: r.UpdatedAt}
|
|
|
|
|
|
|
|
|
|
|
|
// -------- production / equipment --------
|
|
|
|
|
|
onlineDevices := 0
|
|
|
|
|
|
summary := StationSummary{}
|
|
|
|
|
|
equipment := make([]FrontStation, 0, len(r.Equipment))
|
|
|
|
|
|
for _, st := range r.Equipment {
|
|
|
|
|
|
tool := "online"
|
|
|
|
|
|
switch st.Status {
|
|
|
|
|
|
case "running":
|
|
|
|
|
|
tool = "busy"
|
|
|
|
|
|
summary.Running++
|
|
|
|
|
|
case "alarm":
|
|
|
|
|
|
tool = "alarm"
|
|
|
|
|
|
summary.Alarm++
|
|
|
|
|
|
case "offline":
|
|
|
|
|
|
tool = "offline"
|
|
|
|
|
|
summary.Offline++
|
|
|
|
|
|
default:
|
|
|
|
|
|
summary.Idle++
|
|
|
|
|
|
}
|
|
|
|
|
|
if st.Status != "offline" {
|
|
|
|
|
|
onlineDevices += 2
|
|
|
|
|
|
}
|
|
|
|
|
|
equipment = append(equipment, FrontStation{
|
|
|
|
|
|
ID: st.StationNo,
|
|
|
|
|
|
Name: st.Name,
|
|
|
|
|
|
Status: st.Status,
|
|
|
|
|
|
ScanGun: FrontToolState{Status: tool, ProcessedCount: st.DoneToday},
|
|
|
|
|
|
TighteningGun: FrontToolState{Status: tool, CurrentSn: st.CurrentSn, ProcessedCount: st.DoneToday},
|
|
|
|
|
|
CurrentSn: st.CurrentSn,
|
|
|
|
|
|
CurrentOperator: st.CurrentOperator,
|
2026-10-28 10:10:17 +08:00
|
|
|
|
CurrentProcess: st.CurrentProcess,
|
|
|
|
|
|
DoneCount: st.DoneToday,
|
|
|
|
|
|
Paused: st.Paused,
|
|
|
|
|
|
PauseReason: st.PauseReason,
|
2026-09-04 14:18:53 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
f.Equipment = equipment
|
2026-10-29 18:16:53 +08:00
|
|
|
|
|
|
|
|
|
|
// -------- 虚拟工位(OFFLINE):同构映射,但不计入设备在线/总数口径 --------
|
|
|
|
|
|
f.VirtualStations = make([]FrontStation, 0, len(r.VirtualEquipment))
|
|
|
|
|
|
for _, st := range r.VirtualEquipment {
|
|
|
|
|
|
tool := "online"
|
|
|
|
|
|
switch st.Status {
|
|
|
|
|
|
case "running":
|
|
|
|
|
|
tool = "busy"
|
|
|
|
|
|
case "alarm":
|
|
|
|
|
|
tool = "alarm"
|
|
|
|
|
|
case "offline":
|
|
|
|
|
|
tool = "offline"
|
|
|
|
|
|
}
|
|
|
|
|
|
f.VirtualStations = append(f.VirtualStations, FrontStation{
|
|
|
|
|
|
ID: st.StationNo,
|
|
|
|
|
|
Name: st.Name,
|
|
|
|
|
|
Status: st.Status,
|
|
|
|
|
|
ScanGun: FrontToolState{Status: tool, ProcessedCount: st.DoneToday},
|
|
|
|
|
|
TighteningGun: FrontToolState{Status: tool, CurrentSn: st.CurrentSn, ProcessedCount: st.DoneToday},
|
|
|
|
|
|
CurrentSn: st.CurrentSn,
|
|
|
|
|
|
CurrentOperator: st.CurrentOperator,
|
|
|
|
|
|
CurrentProcess: st.CurrentProcess,
|
|
|
|
|
|
DoneCount: st.DoneToday,
|
|
|
|
|
|
Paused: st.Paused,
|
|
|
|
|
|
PauseReason: st.PauseReason,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-04 14:18:53 +08:00
|
|
|
|
f.Production = FrontProduction{
|
|
|
|
|
|
OutputToday: r.Production.OutputToday,
|
|
|
|
|
|
TargetToday: r.Production.TargetToday,
|
|
|
|
|
|
PassCount: r.Production.QualityOk,
|
|
|
|
|
|
TorqueCount: r.Production.TorqueTotal,
|
|
|
|
|
|
InLine: r.Production.InLine,
|
|
|
|
|
|
DeviceOnline: onlineDevices,
|
|
|
|
|
|
DeviceTotal: len(r.Equipment) * 2,
|
2026-10-20 16:36:26 +08:00
|
|
|
|
CycleTimeMin: r.Production.CycleTimeMin,
|
2026-09-04 14:18:53 +08:00
|
|
|
|
StationSummary: summary,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------- warehouse --------
|
2026-10-20 16:36:26 +08:00
|
|
|
|
movements := make([]FrontMovement, 0, len(r.Warehouse.Movements))
|
|
|
|
|
|
for _, m := range r.Warehouse.Movements {
|
|
|
|
|
|
movements = append(movements, FrontMovement{
|
|
|
|
|
|
ID: m.ID, Time: m.Time, Type: m.Type, Material: m.Material,
|
|
|
|
|
|
Qty: m.Qty, Operator: m.Operator, Batch: m.Batch,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-09-04 14:18:53 +08:00
|
|
|
|
f.Warehouse = FrontWarehouse{
|
2026-10-20 16:36:26 +08:00
|
|
|
|
TotalStock: r.Warehouse.TotalQty,
|
|
|
|
|
|
MaterialTypes: r.Warehouse.MaterialTypes,
|
|
|
|
|
|
InboundToday: r.Warehouse.InToday,
|
|
|
|
|
|
OutboundToday: r.Warehouse.OutToday,
|
|
|
|
|
|
LocationUsed: r.Warehouse.LocationUsed,
|
|
|
|
|
|
LocationTotal: r.Warehouse.LocationTotal,
|
|
|
|
|
|
PendingInbound: r.Warehouse.PendingInbound,
|
|
|
|
|
|
PendingOutbound: r.Warehouse.PendingOutbound,
|
|
|
|
|
|
Movements: movements,
|
2026-09-04 14:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------- 当前订单卡片 --------
|
|
|
|
|
|
pr := FrontProgress{ProcessTotal: 12, Status: "待排产"}
|
|
|
|
|
|
if c := r.Production.CurrentOrder; c != nil {
|
|
|
|
|
|
pr = FrontProgress{
|
|
|
|
|
|
OrderNo: c.OrderNo,
|
|
|
|
|
|
ProductName: c.ProductName,
|
|
|
|
|
|
TotalQty: c.TotalQty,
|
|
|
|
|
|
DoneQty: c.DoneQty,
|
|
|
|
|
|
Progress: c.Progress,
|
|
|
|
|
|
Status: c.Status,
|
|
|
|
|
|
CurrentProcess: c.CurrentProcess,
|
|
|
|
|
|
PlanStart: shortDate(c.PlanStart),
|
|
|
|
|
|
PlanEnd: shortDate(c.PlanEnd),
|
|
|
|
|
|
RemainDays: remainDays(c.PlanEnd),
|
|
|
|
|
|
ProcessTotal: 12,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 追溯:取最近完工工件,汇总工序实绩条数 → “全程可追溯”
|
|
|
|
|
|
stepCount := 0
|
|
|
|
|
|
allOk := true
|
|
|
|
|
|
for _, t := range r.Trace.Recent {
|
|
|
|
|
|
stepCount += t.StepCount
|
|
|
|
|
|
if t.NgCount > 0 {
|
|
|
|
|
|
allOk = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
pr.TraceStepCount = stepCount
|
|
|
|
|
|
pr.Traceable = stepCount > 0 && allOk
|
|
|
|
|
|
f.Progress = pr
|
|
|
|
|
|
|
2026-10-29 18:16:53 +08:00
|
|
|
|
// -------- 多订单列表(轮播):进行中工单排前,最多 6 条,首条与 progress 一致 --------
|
|
|
|
|
|
f.ProgressList = make([]FrontProgress, 0, len(r.Production.WorkOrders))
|
|
|
|
|
|
for i, wo := range r.Production.WorkOrders {
|
|
|
|
|
|
if i >= 6 {
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
f.ProgressList = append(f.ProgressList, FrontProgress{
|
|
|
|
|
|
OrderNo: wo.OrderNo,
|
|
|
|
|
|
ProductName: wo.ProductName,
|
|
|
|
|
|
TotalQty: wo.TotalQty,
|
|
|
|
|
|
DoneQty: wo.DoneQty,
|
|
|
|
|
|
Progress: wo.Progress,
|
|
|
|
|
|
Status: wo.Status,
|
|
|
|
|
|
CurrentProcess: wo.CurrentProcess,
|
|
|
|
|
|
PlanStart: shortDate(wo.PlanStart),
|
|
|
|
|
|
PlanEnd: shortDate(wo.PlanEnd),
|
|
|
|
|
|
RemainDays: remainDays(wo.PlanEnd),
|
|
|
|
|
|
ProcessTotal: 12,
|
|
|
|
|
|
TraceStepCount: stepCount,
|
|
|
|
|
|
Traceable: stepCount > 0 && allOk,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-28 10:10:17 +08:00
|
|
|
|
// -------- traces / trends / points / agv / events --------
|
2026-09-04 14:18:53 +08:00
|
|
|
|
f.Traces = r.Trace.Recent
|
|
|
|
|
|
if f.Traces == nil {
|
|
|
|
|
|
f.Traces = []TraceItem{}
|
|
|
|
|
|
}
|
|
|
|
|
|
f.Trends = FrontTrends{Production: r.Trends}
|
|
|
|
|
|
if f.Trends.Production == nil {
|
|
|
|
|
|
f.Trends.Production = []TrendPoint{}
|
|
|
|
|
|
}
|
2026-10-28 10:10:17 +08:00
|
|
|
|
// 点位态:PLC 读取失败时 buildPoints 已降级为 Mock 空态,前端角落标「模拟数据」
|
|
|
|
|
|
f.Points = s.buildPoints(ctx)
|
|
|
|
|
|
if f.Points.Transit == nil {
|
|
|
|
|
|
f.Points.Transit = []InTransit{}
|
|
|
|
|
|
}
|
2026-11-04 19:06:03 +08:00
|
|
|
|
// AGV:真实备料任务 → 稳定码 + 中文显示名(DOCK01..21 → G1L..G10R/JBT21);无假坐标、无假进度
|
2026-10-28 10:10:17 +08:00
|
|
|
|
f.Agv = make([]FrontAgvRobot, 0, len(r.Agv.Robots))
|
|
|
|
|
|
for _, rb := range r.Agv.Robots {
|
|
|
|
|
|
f.Agv = append(f.Agv, FrontAgvRobot{
|
|
|
|
|
|
Code: rb.Code,
|
|
|
|
|
|
Status: rb.Status,
|
2026-11-04 19:06:03 +08:00
|
|
|
|
From: dockCnLabel(dockCodeToCode(rb.FromDock)),
|
|
|
|
|
|
To: dockCnLabel(dockCodeToCode(rb.ToDock)),
|
2026-10-28 10:10:17 +08:00
|
|
|
|
Carrier: rb.Carrier,
|
|
|
|
|
|
TaskNo: rb.TaskNo,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
// 事件流:过滤 NG 结果项(大屏报喜不报忧;负面事件只进语音播报 alarms)
|
|
|
|
|
|
f.Events = make([]EventItem, 0, len(r.Events))
|
|
|
|
|
|
for _, e := range r.Events {
|
|
|
|
|
|
if strings.EqualFold(e.Level, "error") {
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
f.Events = append(f.Events, e)
|
|
|
|
|
|
}
|
2026-10-20 16:36:26 +08:00
|
|
|
|
// 报警仅透传给前端做语音播报(D2),屏幕不渲染(报喜不报忧)。
|
|
|
|
|
|
f.Alarms = r.Alarms
|
|
|
|
|
|
if f.Alarms == nil {
|
|
|
|
|
|
f.Alarms = []AlarmItem{}
|
|
|
|
|
|
}
|
2026-09-04 14:18:53 +08:00
|
|
|
|
return f
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// shortDate "2006-01-02 15:04:05" → "2006-01-02"
|
|
|
|
|
|
func shortDate(s string) string {
|
|
|
|
|
|
if len(s) >= 10 {
|
|
|
|
|
|
return s[:10]
|
|
|
|
|
|
}
|
|
|
|
|
|
return strings.TrimSpace(s)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// remainDays 距交期剩余天数:按自然日差(负数 = 已超期)。
|
|
|
|
|
|
// 工期为空的订单返回 0,前端显示“—”即可。
|
|
|
|
|
|
func remainDays(planEnd string) int {
|
|
|
|
|
|
layout := dashboardTimeLayout
|
|
|
|
|
|
if len(planEnd) == 10 {
|
|
|
|
|
|
layout = "2006-01-02"
|
|
|
|
|
|
}
|
|
|
|
|
|
t, err := time.ParseInLocation(layout, strings.TrimSpace(planEnd), time.Local)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
// 取日期差(跨过当天 0 点即视为到期)
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
|
|
|
|
|
end := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
|
|
|
|
|
|
return int(end.Sub(start).Hours() / 24)
|
|
|
|
|
|
}
|