From 9edf60582263e11ee74fa823af9855f449e8e2f9 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 13 May 2022 09:25:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9dashboard=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../implments/CustOrder.Dashborad.iimpl.go | 441 +++++++++++++----- 1 file changed, 333 insertions(+), 108 deletions(-) diff --git a/services/pln/implments/CustOrder.Dashborad.iimpl.go b/services/pln/implments/CustOrder.Dashborad.iimpl.go index 714644f..e48d6a8 100644 --- a/services/pln/implments/CustOrder.Dashborad.iimpl.go +++ b/services/pln/implments/CustOrder.Dashborad.iimpl.go @@ -301,31 +301,26 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User, workLineId s DashboardData.DashboardDataPic1, err1 = impl.SelectPic1(user, dayModel, workLineId) wg.Done() // 操作完成,减少一个计数 }(&wg) - //图例002 go func(wg *sync.WaitGroup) { DashboardData.DashboardDataPic2, err2 = impl.SelectDefectNumber(user, days, workLineId) wg.Done() // 操作完成,减少一个计数 }(&wg) - //图例003 go func(wg *sync.WaitGroup) { - DashboardData.DashboardDataPic3, err3 = impl.SelectPic3(user, DayModelHours, dayModelStartHour, dayModelEndHour, startDayTime, endDayTime, timeBeat, personNum, workLineId) + DashboardData.DashboardDataPic3, err3 = impl.SelectPic3(user, DayModelHours, dayModel, startDayTime, endDayTime, timeBeat, personNum, workLineId) wg.Done() // 操作完成,减少一个计数 }(&wg) - //图例004 go func(wg *sync.WaitGroup) { DashboardData.DashboardDataPic4, err4 = impl.CountTarget(user, workLineId) wg.Done() // 操作完成,减少一个计数 }(&wg) - //计算当前节拍,及其平均 go func(wg *sync.WaitGroup) { DashboardData.TeamTemPo, DashboardData.PerHourTemPo, err5 = impl.SelectTeamTemPo(user, dayModel, personNum, startDayTime, WorkShift, workLineId) wg.Done() // 操作完成,减少一个计数 }(&wg) - go func(wg *sync.WaitGroup) { DashboardData.DashboardDataStatus, err6 = impl.SelectAndonInfo(user) wg.Done() // 操作完成,减少一个计数 @@ -548,94 +543,97 @@ func (impl *CustOrderServiceImplement) InitDayModelList(dayModel *baseModel.DayM element.Duration = element.End.Sub(element.Start) dayModelList.PushBack(element) } - - element.Start = date.Add(time.Duration(dayModel.S2Beg) * time.Second) - if dayModel.S2B1Beg != 0 { - var end time.Time - element.End = date.Add(time.Duration(dayModel.S2B1Beg) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S2B1End) * time.Second) - if dayModel.S2B2Beg != 0 { - element.Start = end - element.End = date.Add(time.Duration(dayModel.S2B2Beg) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S2B2End) * time.Second) - } - if dayModel.S2B3Beg != 0 { - element.Start = end - element.End = date.Add(time.Duration(dayModel.S2B3Beg) * time.Second) + if dayModel.S2Toggle { + element.Start = date.Add(time.Duration(dayModel.S2Beg) * time.Second) + if dayModel.S2B1Beg != 0 { + var end time.Time + element.End = date.Add(time.Duration(dayModel.S2B1Beg) * time.Second) element.Duration = element.End.Sub(element.Start) dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S2B3End) * time.Second) - } - if dayModel.S2B4Beg != 0 { + end = date.Add(time.Duration(dayModel.S2B1End) * time.Second) + if dayModel.S2B2Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S2B2Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S2B2End) * time.Second) + } + if dayModel.S2B3Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S2B3Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S2B3End) * time.Second) + } + if dayModel.S2B4Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S2B4Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S2B4End) * time.Second) + } + if dayModel.S2B5Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S2B5Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S2B5End) * time.Second) + } element.Start = end - element.End = date.Add(time.Duration(dayModel.S2B4Beg) * time.Second) + element.End = date.Add(time.Duration(dayModel.S2End) * time.Second) element.Duration = element.End.Sub(element.Start) dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S2B4End) * time.Second) - } - if dayModel.S2B5Beg != 0 { - element.Start = end - element.End = date.Add(time.Duration(dayModel.S2B5Beg) * time.Second) + } else { + element.End = date.Add(time.Duration(dayModel.S2End) * time.Second) element.Duration = element.End.Sub(element.Start) dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S2B5End) * time.Second) } - element.Start = end - element.End = date.Add(time.Duration(dayModel.S2End) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) - } else { - element.End = date.Add(time.Duration(dayModel.S2End) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) } - element.Start = date.Add(time.Duration(dayModel.S3Beg) * time.Second) - if dayModel.S3B1Beg != 0 { - var end time.Time - element.End = date.Add(time.Duration(dayModel.S3B1Beg) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S3B1End) * time.Second) - if dayModel.S3B2Beg != 0 { - element.Start = end - element.End = date.Add(time.Duration(dayModel.S3B2Beg) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S3B2End) * time.Second) - } - if dayModel.S3B3Beg != 0 { - element.Start = end - element.End = date.Add(time.Duration(dayModel.S3B3Beg) * time.Second) + if dayModel.S3Toggle { + element.Start = date.Add(time.Duration(dayModel.S3Beg) * time.Second) + if dayModel.S3B1Beg != 0 { + var end time.Time + element.End = date.Add(time.Duration(dayModel.S3B1Beg) * time.Second) element.Duration = element.End.Sub(element.Start) dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S3B3End) * time.Second) - } - if dayModel.S3B4Beg != 0 { + end = date.Add(time.Duration(dayModel.S3B1End) * time.Second) + if dayModel.S3B2Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S3B2Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S3B2End) * time.Second) + } + if dayModel.S3B3Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S3B3Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S3B3End) * time.Second) + } + if dayModel.S3B4Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S3B4Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S3B4End) * time.Second) + } + if dayModel.S3B5Beg != 0 { + element.Start = end + element.End = date.Add(time.Duration(dayModel.S3B5Beg) * time.Second) + element.Duration = element.End.Sub(element.Start) + dayModelList.PushBack(element) + end = date.Add(time.Duration(dayModel.S3B5End) * time.Second) + } element.Start = end - element.End = date.Add(time.Duration(dayModel.S3B4Beg) * time.Second) + element.End = date.Add(time.Duration(dayModel.S3End) * time.Second) element.Duration = element.End.Sub(element.Start) dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S3B4End) * time.Second) - } - if dayModel.S3B5Beg != 0 { - element.Start = end - element.End = date.Add(time.Duration(dayModel.S3B5Beg) * time.Second) + } else { + element.End = date.Add(time.Duration(dayModel.S3End) * time.Second) element.Duration = element.End.Sub(element.Start) dayModelList.PushBack(element) - end = date.Add(time.Duration(dayModel.S3B5End) * time.Second) } - element.Start = end - element.End = date.Add(time.Duration(dayModel.S3End) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) - } else { - element.End = date.Add(time.Duration(dayModel.S3End) * time.Second) - element.Duration = element.End.Sub(element.Start) - dayModelList.PushBack(element) } } return dayModelList @@ -902,7 +900,7 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *b productFamilyRelateMap := make(map[string]map[string]interface{}) productFamilyMeterMap := make(map[string]float64) now := time.Now() - //now, _ := time.ParseInLocation(grmi.DateTimeOutFormat, "2022-03-30 23:00:00", utils.TimezoneLocation) + //now, _ := time.ParseInLocation(grmi.DateTimeOutFormat, "2022-04-28 23:00:00", utils.TimezoneLocation) endTime := now.Format(grmi.DateOutFormat) + " 23:59:59" todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" dateTimeLi := make([]int, 0, now.Hour()) @@ -1059,8 +1057,11 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *b } } displayHourLi := make([]string, 0, len(productFamilyAccomplishMap)) - for hour, _ := range productFamilyAccomplishMap { - displayHourLi = append(displayHourLi, strconv.Itoa(hour)+"时") + for hour := 0; hour < 24; hour++ { + _, exist := productFamilyAccomplishMap[hour] + if exist { + displayHourLi = append(displayHourLi, strconv.Itoa(hour)+"时") + } } result = model.CutLine1{ TimeLi: displayHourLi, @@ -1093,7 +1094,8 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *b meter := productFamilyMeterMap[productFamilyProductData.ProductFamilyId] var percent float64 if productFamilyProductData.Qty != 0 && usedTime != 0 && hourAllUsedTime != 0 { - percent = meter / (float64(usedTime) / float64(productFamilyProductData.Qty)) * (float64(usedTime) / float64(hourAllUsedTime)) + percent = float64(productFamilyProductData.Qty) / (meter * (float64(usedTime) / float64(hourAllUsedTime))) + //percent = meter / (float64(usedTime) / float64(productFamilyProductData.Qty)) * (float64(usedTime) / float64(hourAllUsedTime)) } hourPercent += percent } @@ -1106,26 +1108,71 @@ func (impl *CustOrderServiceImplement) GetUsefulTime(start, end time.Time, timeL var duration int for element := timeLine.Front(); element != nil; element = element.Next() { listElement := element.Value.(model.ListElement) - if listElement.End.Before(start) { - continue - } else if listElement.Start.After(end) { - continue - } else if (listElement.Start.After(start) || listElement.Start.Equal(start)) && (listElement.End.Before(end) || listElement.End.Equal(end)) { - duration += int(listElement.End.Sub(listElement.Start).Seconds()) - } else if listElement.Start.Before(start) && listElement.End.After(start) { - duration += int(listElement.End.Sub(start).Seconds()) - } else if listElement.Start.After(start) && listElement.End.After(end) { - duration += int(end.Sub(listElement.Start).Seconds()) + //比较开始时间 + if listElement.Start.Before(start) { + + /* + /----------------------/ start ---- end + + /----------------------/ listElement + + */ + if listElement.End.After(start) && listElement.End.Before(end) { + + duration += int(listElement.End.Sub(start).Seconds()) + } + + /* + /----------------------/ start ---- end + + /---------------------------------/ listElement + + */ + if listElement.End.After(end) { + duration += int(end.Sub(start).Seconds()) + } + } else if listElement.Start.After(start) && listElement.Start.Before(end) { + /* + /----------------------/ start ---- end + + /-----------/ listElement + + */ + + if listElement.End.Before(end) { + duration += int(listElement.End.Sub(listElement.Start).Seconds()) + } + + /* + /----------------------/ start ---- end + + /----------------------/ listElement + + */ + if listElement.End.After(end) { + duration += int(end.Sub(listElement.Start).Seconds()) + } } } return duration } //图例3 -func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHours []string, dayModelStartHour time.Time, dayModelEndHour time.Time, startDayTime time.Time, endDayTime time.Time, timeBeat float64, personNum int, workLineId string) (model.PerDashboardData, error) { +func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHours []string, dayModel *baseModel.DayModel, startDayTime time.Time, endDayTime time.Time, timeBeat float64, personNum int, workLineId string) (model.PerDashboardData, error) { engine := db.Eloquent.Master() session := engine.NewSession() defer session.Close() + custOrderDao := dal.NewCustOrderDAO(session, user.PlantNr, user.UserId) + productFamilyDao := meDal.NewProductFamilyDAO(session, user.PlantNr, user.UserId) + productFamilyRelateDao := meDal.NewProductFamilyRelateDAO(session, user.PlantNr, user.UserId) + serialOrderDao := omDal.NewSerialOrderDAO(session, user.PlantNr, user.UserId) + productFamilyMap := make(map[string]*meModel.ProductFamily) + productFamilyRelateMap := make(map[string]map[string]interface{}) + productFamilyMeterMap := make(map[string]float64) + now := time.Now() + //now, _ := time.ParseInLocation(grmi.DateTimeOutFormat, "2022-04-28 23:00:00", utils.TimezoneLocation) + endTime := now.Format(grmi.DateOutFormat) + " 23:59:59" + todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" packDao := jitDal.NewPackOrderDAO(session, user.PlantNr, user.UserId) //图例003 DashboardData3 := model.PerDashboardData{} @@ -1142,6 +1189,183 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou for _, v := range workLineLi { workLineIds = append(workLineIds, v.WorkLineid) } + + timeModelList := impl.InitDayModelList(dayModel, startDayTime) + + // 查询正在正在生产的客户订单 + custOrderLi, err := custOrderDao.SelectRunningCustOrder(workLineId) + + if err != nil { + return DashboardData3, grmi.NewBusinessError("查询正在生产的客户订单失败, 错误:" + err.Error()) + } + + if len(custOrderLi) > 0 { + custOrder := custOrderLi[0] + productFamily, err := productFamilyDao.SelectOne(custOrder.ProductFamilyId) + if err != nil { + return DashboardData3, grmi.NewBusinessError("查询派生数据失败, 错误:" + err.Error()) + } + if productFamily == nil { + return DashboardData3, grmi.NewBusinessError("客户订单派生不存在, 派生ID:" + custOrder.ProductFamilyId) + } + if productFamily.Jph == 0 { + return DashboardData3, grmi.NewBusinessError("派生JPH为0 派生ID:" + custOrder.ProductFamilyId) + } + productFamilyMeterMap[custOrder.ProductFamilyId] = float64(3600) / productFamily.Jph + productFamilyMap[custOrder.ProductFamilyId] = productFamily + productLi, err := productFamilyRelateDao.SelectProductByFamilyId(custOrder.ProjectId, custOrder.ProductFamilyId) + if err != nil { + return DashboardData3, grmi.NewBusinessError("查询派生下总成数据失败, 错误:" + err.Error()) + } + if len(productLi) == 0 { + return DashboardData3, grmi.NewBusinessError("派生下未关联需要生产的座椅总成, 派生ID:" + custOrder.ProductFamilyId) + } + productFamilyRelateMap[custOrder.ProductFamilyId] = make(map[string]interface{}, len(productLi)) + for _, product := range productLi { + productFamilyRelateMap[custOrder.ProductFamilyId][product.ProductId] = nil + } + } + + // 查询客户订单 两类: + // 1. 今天开始时间 < 实际结束时间 < 当前时间 状态 > 26 && != 98 + // 2. 实际结束时间为空 实际开始时间 < 当前时间 状态 > 26 && != 98 + custOrderDataLi, err := custOrderDao.SelectProduceOrder(todayStart, endTime, workLineId) + if err != nil { + return DashboardData3, grmi.NewBusinessError("查询客户订单失败, 错误:" + err.Error()) + } + + productFamilyAccomplishMap := make(map[int]map[string]model.HourProductData) + for _, custOrderData := range custOrderDataLi { + productFamilyId := custOrderData.CustOrder.ProductFamilyId + productFamily, exist := productFamilyMap[productFamilyId] + if !exist { + productFamily, err = productFamilyDao.SelectOne(productFamilyId) + if err != nil { + return DashboardData3, grmi.NewBusinessError("查询派生数据失败, 错误:" + err.Error()) + } + if productFamily == nil { + return DashboardData3, grmi.NewBusinessError("客户订单中派生不存在, 派生Id:" + productFamilyId + ", 客户订单Id:" + custOrderData.CustOrder.CustOrderId) + } + if productFamily.Jph == 0 { + return DashboardData3, grmi.NewBusinessError("派生JPH为0 派生ID:" + productFamilyId) + } + productLi, err := productFamilyRelateDao.SelectProductByFamilyId(custOrderData.CustOrder.ProjectId, productFamilyId) + if err != nil { + return DashboardData3, grmi.NewBusinessError("查询派生下总成数据失败, 错误:" + err.Error()) + } + if len(productLi) == 0 { + return DashboardData3, grmi.NewBusinessError("派生下未关联需要生产的座椅总成, 派生ID:" + productFamilyId) + } + productFamilyRelateMap[productFamilyId] = make(map[string]interface{}, len(productLi)) + for _, product := range productLi { + productFamilyRelateMap[productFamilyId][product.ProductId] = nil + } + productFamilyMap[productFamilyId] = productFamily + productFamilyMeterMap[productFamilyId] = float64(3600) / productFamily.Jph + } + // 查询客户订单下的工单 + serialOrderDataLi, err := serialOrderDao.SelectByCustOrderIdForDashboard(custOrderData.CustOrder.CustOrderId, todayStart, endTime) + if err != nil { + return DashboardData3, grmi.NewBusinessError("查询客户订单下工单失败, 错误:" + err.Error()) + } + // 记录生产每个台套下面的工单数量 + syncKeyMap := make(map[string][]omModel.SerialOrder) + syncKeyAccomplishTimeMap := make(map[string]time.Time) + for _, serialOrder := range serialOrderDataLi { + _, exist = syncKeyMap[serialOrder.SyncKey] + if !exist { + syncKeyMap[serialOrder.SyncKey] = make([]omModel.SerialOrder, 0, len(productFamilyRelateMap[productFamilyId])) + } + syncKeyMap[serialOrder.SyncKey] = append(syncKeyMap[serialOrder.SyncKey], serialOrder) + } + // 找到每个台套的最后完成时间 + for syncKey, orderLi := range syncKeyMap { + if len(orderLi) == len(productFamilyRelateMap[productFamilyId]) { + var match = true + orderArtIdMap := make(map[string]interface{}) + for _, order := range orderLi { + orderArtIdMap[order.ArtId] = nil + } + for artId, _ := range productFamilyRelateMap[productFamilyId] { + _, exist = orderArtIdMap[artId] + if !exist { + match = false + break + } + } + if !match { + continue + } + var accomplishTime time.Time + for _, serialOrder := range orderLi { + if serialOrder.ActEndTime.Restore().After(accomplishTime) { + accomplishTime = serialOrder.ActEndTime.Restore() + } + } + syncKeyAccomplishTimeMap[syncKey] = accomplishTime + } + } + // 记录每个小时完成的数量和时间 + for _, accomplishTime := range syncKeyAccomplishTimeMap { + hour := accomplishTime.Hour() + hourProductMap, exist := productFamilyAccomplishMap[hour] + if !exist { + productFamilyAccomplishMap[hour] = make(map[string]model.HourProductData) + hourProductMap = productFamilyAccomplishMap[hour] + } + productFamilyData, exist := hourProductMap[productFamilyId] + if !exist { + hourProductMap[productFamilyId] = model.HourProductData{ + ProductFamilyId: productFamilyId, + Qty: 1, + LastDoneTime: accomplishTime, + } + } else { + productFamilyData.Qty++ + if productFamilyData.LastDoneTime.Before(accomplishTime) { + productFamilyData.LastDoneTime = accomplishTime + } + hourProductMap[productFamilyId] = productFamilyData + } + productFamilyAccomplishMap[hour] = hourProductMap + } + } + //定义动态JPH + jphMap := make(map[string]float64) + for hour := 0; hour < 24; hour++ { + + key := utils.TimeFormat(startDayTime.Add(time.Duration(hour)*time.Hour), "yyyy-MM-dd HH:00") + hourData, exist := productFamilyAccomplishMap[hour] + if !exist { + continue + } + var hourPercent float64 + productDataLi := make([]model.HourProductData, 0, len(hourData)) + for _, data := range hourData { + productDataLi = append(productDataLi, data) + } + impl.QuickSortProductData(productDataLi) + currentTime := startDayTime.Add(time.Hour * time.Duration(hour)) + var hourAllUsedTime int + for _, productFamilyProductData := range productDataLi { + usedTime := impl.GetUsefulTime(currentTime, productFamilyProductData.LastDoneTime, timeModelList) + currentTime = productFamilyProductData.LastDoneTime + hourAllUsedTime += usedTime + } + currentTime = startDayTime.Add(time.Hour * time.Duration(hour)) + for _, productFamilyProductData := range productDataLi { + usedTime := impl.GetUsefulTime(currentTime, productFamilyProductData.LastDoneTime, timeModelList) + currentTime = productFamilyProductData.LastDoneTime + meter := productFamilyMeterMap[productFamilyProductData.ProductFamilyId] + var percent float64 + if productFamilyProductData.Qty != 0 && usedTime != 0 && hourAllUsedTime != 0 { + percent = (meter * (float64(usedTime) / float64(hourAllUsedTime))) + //percent = meter / (float64(usedTime) / float64(productFamilyProductData.Qty)) * (float64(usedTime) / float64(hourAllUsedTime)) + } + hourPercent += percent + } + jphMap[key] = hourPercent + } //查询当天所有的包装单情况 jitData, err := packDao.SelectUserClosePackOrder(utils.TimeFormat(startDayTime, "yyyy-MM-dd HH:mm:ss"), utils.TimeFormat(endDayTime, "yyyy-MM-dd HH:mm:ss"), workLineIds) if err != nil { @@ -1151,15 +1375,7 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou for _, v := range jitData { - key := utils.TimeFormat(v.OpenTime.Restore(), "yyyy-MM-dd HH:00") - - if dayModelStartHour.Unix() > v.OpenTime.Restore().Unix() { - key = utils.TimeFormat(dayModelStartHour, "yyyy-MM-dd HH:00") - } - - if dayModelEndHour.Unix() < v.OpenTime.Restore().Unix() { - key = utils.TimeFormat(dayModelEndHour, "yyyy-MM-dd HH:00") - } + key := utils.TimeFormat(v.CloseTime.Restore(), "yyyy-MM-dd HH:00") _, ok := jitMap[key] if ok { @@ -1168,22 +1384,31 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou jitMap[key] = 1 } } - for _, v := range DayModelHours { - key := v + for i := 0; i < len(DayModelHours); i++ { + key := DayModelHours[i] val, ok := jitMap[key] one := model.DashboardData{} - one.Date = v + one.Date = DayModelHours[i] if ok { - one.Val = utils.Decimal(float64(val)/float64(personNum), 2) + one.Val = utils.Decimal((float64(val)/float64(personNum)), 2) } else { one.Val = 0 } DashboardData3.DashboardData1 = append(DashboardData3.DashboardData1, one) two := model.DashboardData{} - two.Date = v - two.Val = utils.Decimal(float64((3600/timeBeat)/float64(personNum))*100, 2) + two.Date = DayModelHours[i] + timeBeat, ok := jphMap[key] + if !ok { + two.Val = 0 + } else { + if timeBeat > 0 { + two.Val = utils.Decimal(float64((3600/timeBeat)/float64(personNum)), 2) + } else { + two.Val = 0 + } + } DashboardData3.DashboardData2 = append(DashboardData3.DashboardData2, two) } return DashboardData3, nil @@ -1203,4 +1428,4 @@ func (impl *CustOrderServiceImplement) SelectAndonInfo(user *global.User) (int, return 1, nil } return 0, nil -} +} \ No newline at end of file