From 73eec89cf84f1eb7394ee2d5bf3f66bfcb2c6002 Mon Sep 17 00:00:00 2001 From: "DESKTOP-H7A6KL3\\wenzh" Date: Thu, 11 Aug 2022 09:04:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SerialOrderOPDetailRecvDataLst.dao.impl.go | 2 +- .../pln/implments/CustOrder.Dashborad.impl.go | 448 ++++++------------ 2 files changed, 151 insertions(+), 299 deletions(-) diff --git a/dao/om/implments/SerialOrderOPDetailRecvDataLst.dao.impl.go b/dao/om/implments/SerialOrderOPDetailRecvDataLst.dao.impl.go index c244152..f30f30e 100644 --- a/dao/om/implments/SerialOrderOPDetailRecvDataLst.dao.impl.go +++ b/dao/om/implments/SerialOrderOPDetailRecvDataLst.dao.impl.go @@ -409,7 +409,7 @@ func (impl *SerialOrderOPDetailRecvDataLstDAOImplement) GetOpRecvDataByPO(serial ******************************************************************************/ func (impl *SerialOrderOPDetailRecvDataLstDAOImplement) SelectOneByAssembly(RecvData string) (*model.SerialOrderOPDetailRecvDataLst, error) { var data model.SerialOrderOPDetailRecvDataLst - ok, err := impl.session.Table(impl.meta.TableName).Where("RecvData = ? and StepType = ?", RecvData, "扫码校验").Get(&data) + ok, err := impl.session.Table(impl.meta.TableName).Where("PlantNr = ? and RecvData = ? and StepType = ?",impl.plantNr, RecvData, "扫码校验").Get(&data) if err != nil { return nil, grmi.NewDataBaseError(err) } diff --git a/services/pln/implments/CustOrder.Dashborad.impl.go b/services/pln/implments/CustOrder.Dashborad.impl.go index d831061..61cd4ea 100644 --- a/services/pln/implments/CustOrder.Dashborad.impl.go +++ b/services/pln/implments/CustOrder.Dashborad.impl.go @@ -18,6 +18,7 @@ import ( meModel "LAPP_ACURA_MOM_BACKEND/models/me" model "LAPP_ACURA_MOM_BACKEND/models/pln" "LAPP_ACURA_MOM_BACKEND/utils" + "LAPP_ACURA_MOM_BACKEND/web/middleware/glog" "container/list" "errors" "strconv" @@ -132,13 +133,6 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User, workLineId s if dayModel == nil { return nil, grmi.NewBusinessError("关联的日模型不存在") } - var dayModelStartTime int - var dayModelEndTime int - nowTime := time.Now() - var WorkShift int - _ = WorkShift - //构建开始时间和结束时间 - startDayTime := utils.GetZeroTime(time.Now()) if dayModel.WorkShiftToggle { if dayModel.S1WorkShiftNr == 0 { return nil, grmi.NewBusinessError("绑定的日模型错误") @@ -149,25 +143,8 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User, workLineId s return nil, err } if s1WorkShift != nil { - if dayModelStartTime > 0 { - if dayModelStartTime > dayModel.S1Beg { - dayModelStartTime = dayModel.S1Beg - } - } else { - dayModelStartTime = dayModel.S1Beg - } - if dayModelEndTime != 0 { - if dayModelEndTime < dayModel.S1End { - dayModelEndTime = dayModel.S1End - } - } else { - dayModelEndTime = dayModel.S1End - } - dayModelStartHour1 := startDayTime.Add(time.Duration(dayModel.S1Beg) * time.Second) - dayModelEndHour1 := startDayTime.Add(time.Duration(dayModel.S1End) * time.Second) - if nowTime.Unix() >= dayModelStartHour1.Unix() && nowTime.Unix() <= dayModelEndHour1.Unix() { - WorkShift = 1 - } + dayModel.S1WorkShift = *s1WorkShift + } if dayModel.S2WorkShiftNr != 0 { @@ -177,26 +154,7 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User, workLineId s } if s2WorkShift != nil { dayModel.S2WorkShift = *s2WorkShift - if dayModelStartTime > 0 { - if dayModelStartTime > dayModel.S2Beg { - dayModelStartTime = dayModel.S2Beg - } - } else { - dayModelStartTime = dayModel.S2Beg - } - if dayModelEndTime != 0 { - if dayModelEndTime < dayModel.S2End { - dayModelEndTime = dayModel.S2End - } - } else { - dayModelEndTime = dayModel.S2End - } - dayModelStartHour2 := startDayTime.Add(time.Duration(dayModel.S2Beg) * time.Second) - dayModelEndHour2 := startDayTime.Add(time.Duration(dayModel.S2End) * time.Second) - if nowTime.Unix() >= dayModelStartHour2.Unix() && nowTime.Unix() <= dayModelEndHour2.Unix() { - WorkShift = 2 - } } } @@ -208,113 +166,120 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User, workLineId s if s3WorkShift != nil { dayModel.S3WorkShift = *s3WorkShift - if dayModelStartTime > 0 { - if dayModelStartTime > dayModel.S3Beg { - dayModelStartTime = dayModel.S3Beg - } - } else { - dayModelStartTime = dayModel.S3Beg - } - if dayModelEndTime != 0 { - if dayModelEndTime < dayModel.S3End { - dayModelEndTime = dayModel.S3End - } - } else { - dayModelEndTime = dayModel.S3End - } - dayModelStartHour3 := startDayTime.Add(time.Duration(dayModel.S3Beg) * time.Second) - dayModelEndHour3 := startDayTime.Add(time.Duration(dayModel.S3End) * time.Second) - if nowTime.Unix() >= dayModelStartHour3.Unix() && nowTime.Unix() <= dayModelEndHour3.Unix() { - WorkShift = 3 - } } } - } else { - if dayModelStartTime > 0 { - if dayModelStartTime > dayModel.S1Beg { - dayModelStartTime = dayModel.S1Beg - } - } else { - dayModelStartTime = dayModel.S1Beg - } - if dayModelEndTime != 0 { - if dayModelEndTime < dayModel.S1End { - dayModelEndTime = dayModel.S1End - } - } else { - dayModelEndTime = dayModel.S1End - } - dayModelStartHour1 := startDayTime.Add(time.Duration(dayModel.S1Beg) * time.Second) - dayModelEndHour1 := startDayTime.Add(time.Duration(dayModel.S1End) * time.Second) - if nowTime.Unix() >= dayModelStartHour1.Unix() && nowTime.Unix() <= dayModelEndHour1.Unix() { - WorkShift = 1 - } + } + + DashboardData := model.DashboardPic{} + //当班人数 + DashboardData.TemPoPerson = personNum + DashboardData.TeamTemPo = utils.ValueToFloat(personNum, 0.0) + //节拍 + DashboardData.CurrentTempo = timeBeat + DashboardData.IppmTarge = ippmTarge + DashboardData.DateTimeNow = utils.TimeFormat(time.Now(), "yyyy-MM-dd HH:00") + + var WorkShift int + _ = WorkShift + //构建开始时间和结束时间 + startDayTime := utils.GetZeroTime(time.Now()) + //判断当前时间,决定取时间模型 + //nowUnix := int(time.Now().Unix() - startDayTime.Unix()) + //if nowUnix < dayModel.S1Beg { + // startDayTime = startDayTime.AddDate(0, 0, -1) + // nowUnix += 86400 + //} + now := time.Now() + var startTime, endTime time.Time + var usePreDay, notUseToday bool + if dayModel.WorkShiftToggle { - if dayModelStartTime > 0 { - if dayModelStartTime > dayModel.S2Beg { - dayModelStartTime = dayModel.S2Beg + startTime = startDayTime.Add(time.Duration(dayModel.S1WorkShift.SBeg) * time.Second) + //endTime = startDayTime.Add(time.Duration(dayModel.S1WorkShift.SEnd) * time.Second) + //if dayModel.S2WorkShiftNr != 0 { + // endTime = startDayTime.Add(time.Duration(dayModel.S2WorkShift.SEnd) * time.Second) + //} + //if dayModel.S3WorkShiftNr != 0 { + // endTime = startDayTime.Add(time.Duration(dayModel.S3WorkShift.SEnd) * time.Second) + //} + } else { + startTime = startDayTime.Add(time.Duration(dayModel.S1Beg) * time.Second) + endTime = startDayTime.Add(time.Duration(dayModel.S1End) * time.Second) + } + if now.Unix() < startTime.Unix() { + notUseToday = true + } + if notUseToday { + preDayStartTime := startDayTime.AddDate(0, 0, -1) + if dayModel.WorkShiftToggle { + startTime = preDayStartTime.Add(time.Duration(dayModel.S1WorkShift.SBeg) * time.Second) + endTime = preDayStartTime.Add(time.Duration(dayModel.S1WorkShift.SEnd) * time.Second) + if dayModel.S2WorkShiftNr != 0 { + endTime = preDayStartTime.Add(time.Duration(dayModel.S2WorkShift.SEnd) * time.Second) } - } else { - dayModelStartTime = dayModel.S2Beg - } - if dayModelEndTime != 0 { - if dayModelEndTime < dayModel.S2End { - dayModelEndTime = dayModel.S2End + if dayModel.S3WorkShiftNr != 0 { + endTime = preDayStartTime.Add(time.Duration(dayModel.S3WorkShift.SEnd) * time.Second) } } else { - dayModelEndTime = dayModel.S2End - } - - dayModelStartHour2 := startDayTime.Add(time.Duration(dayModel.S2Beg) * time.Second) - dayModelEndHour2 := startDayTime.Add(time.Duration(dayModel.S2End) * time.Second) - if nowTime.Unix() >= dayModelStartHour2.Unix() && nowTime.Unix() <= dayModelEndHour2.Unix() { - WorkShift = 2 - } + startTime = preDayStartTime.Add(time.Duration(dayModel.S1Beg) * time.Second) + endTime = preDayStartTime.Add(time.Duration(dayModel.S1End) * time.Second) + if dayModel.S2Toggle { + endTime = preDayStartTime.Add(time.Duration(dayModel.S2End) * time.Second) - if dayModelStartTime > 0 { - if dayModelStartTime > dayModel.S3Beg { - dayModelStartTime = dayModel.S3Beg } - } else { - dayModelStartTime = dayModel.S3Beg - } - if dayModelEndTime != 0 { - if dayModelEndTime < dayModel.S3End { - dayModelEndTime = dayModel.S3End + if dayModel.S3Toggle { + endTime = preDayStartTime.Add(time.Duration(dayModel.S3End) * time.Second) } - } else { - dayModelEndTime = dayModel.S3End } - dayModelStartHour3 := startDayTime.Add(time.Duration(dayModel.S3Beg) * time.Second) - dayModelEndHour3 := startDayTime.Add(time.Duration(dayModel.S3End) * time.Second) - if nowTime.Unix() >= dayModelStartHour3.Unix() && nowTime.Unix() <= dayModelEndHour3.Unix() { - WorkShift = 3 + if now.Unix() >= startTime.Unix() && now.Unix() <= endTime.Unix() { + usePreDay = true } } - if dayModelEndTime < dayModelStartTime { + if now.Unix() > endTime.Unix() { + notUseToday = true + } + glog.InfoExtln("DashboardData", "notUseToday", notUseToday) + glog.InfoExtln("DashboardData", "usePreDay", usePreDay) + if notUseToday && !usePreDay { + return DashboardData, nil + } + var useDayStartTime time.Time + if usePreDay { + useDayStartTime = startDayTime.AddDate(0, 0, -1) + } else { + useDayStartTime = startDayTime + } + + glog.InfoExtln("DashboardData", "WorkShift", WorkShift) + glog.InfoExtln("DashboardData", "startTime", startTime) + glog.InfoExtln("DashboardData", "endTime", endTime) + if startTime.Unix() > endTime.Unix() { return nil, errors.New("日模型开始时间大于结束时间") } - dayModelStartHour := startDayTime.Add(time.Duration(dayModelStartTime) * time.Second) + //dayModelStartHour := startDayTime.Add(time.Duration(dayModelStartTime) * time.Second) //dayModelEndHour := startDayTime.Add(time.Duration(dayModelEndTime) * time.Second) - endDayTime := utils.GetZeroTime(time.Now().AddDate(0, 0, 1)) - nowEndHour := time.Now() - DayModelHours, err := utils.GetHoursData(dayModelStartHour, nowEndHour) + //glog.InfoExtln("DashboardData","dayModelStartHour",dayModelStartHour) + //glog.InfoExtln("DashboardData","dayModelEndHour",dayModelEndHour) + // + //nowEndHour := time.Now() + glog.InfoExtln("DashboardData", "startTime", startTime) + glog.InfoExtln("DashboardData", "now", now) + DayModelHours, err := utils.GetHoursData(startTime, now) - _ = endDayTime - _ = DayModelHours + //_ = DayModelHours if err != nil { return nil, err } - DashboardData := model.DashboardPic{} + var err1, err2, err3, err4, err5, err6 error var wg sync.WaitGroup wg.Add(7) //图例001 go func(wg *sync.WaitGroup) { - DashboardData.DashboardDataPic1, err1 = impl.SelectPic1(user, dayModel, workLineId) + DashboardData.DashboardDataPic1, err1 = impl.SelectPic1(user, dayModel, workLineId, startTime, endTime, useDayStartTime) wg.Done() // 操作完成,减少一个计数 }(&wg) //图例002 @@ -324,17 +289,17 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User, workLineId s }(&wg) //图例003 go func(wg *sync.WaitGroup) { - DashboardData.DashboardDataPic3, err3 = impl.SelectPic3(user, DayModelHours, dayModel, jPHPercent, startDayTime, endDayTime, timeBeat, personNum, workLineId) + DashboardData.DashboardDataPic3, err3 = impl.SelectPic3(user, DayModelHours, dayModel, jPHPercent, startTime, now, timeBeat, personNum, workLineId, useDayStartTime) wg.Done() // 操作完成,减少一个计数 }(&wg) //图例004 go func(wg *sync.WaitGroup) { - DashboardData.DashboardDataPic4, err4 = impl.CountTarget(user, dayModel, WorkShift, workLineId) + DashboardData.DashboardDataPic4, err4 = impl.CountTarget(user, dayModel, WorkShift, startTime, now, workLineId) wg.Done() // 操作完成,减少一个计数 }(&wg) //计算当前节拍,及其平均 go func(wg *sync.WaitGroup) { - DashboardData.TeamTemPo, DashboardData.PerHourTemPo, err5 = impl.SelectTeamTemPo(user, dayModel, jPHPercent, personNum, startDayTime, WorkShift, workLineId) + DashboardData.TeamTemPo, DashboardData.PerHourTemPo, err5 = impl.SelectTeamTemPo(user, dayModel, jPHPercent, personNum, startTime, endTime, WorkShift, workLineId, useDayStartTime) wg.Done() // 操作完成,减少一个计数 }(&wg) go func(wg *sync.WaitGroup) { @@ -368,13 +333,7 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User, workLineId s if err6 != nil { return nil, err6 } - //当班人数 - DashboardData.TemPoPerson = personNum - //节拍 - DashboardData.CurrentTempo = timeBeat - DashboardData.IppmTarge = ippmTarge - DashboardData.DateTimeNow = utils.TimeFormat(time.Now(), "yyyy-MM-dd HH:00") return DashboardData, err } @@ -984,11 +943,10 @@ func (impl *CustOrderServiceImplement) SelectDefectNumber(user *global.User, day return result, nil } -func (impl *CustOrderServiceImplement) CountTarget(user *global.User, dayModel *baseModel.DayModel, WorkShift int, workLineId string) (model.TargetItem, error) { +func (impl *CustOrderServiceImplement) CountTarget(user *global.User, dayModel *baseModel.DayModel, WorkShift int, startDayTime time.Time, endDayTime time.Time, workLineId string) (model.TargetItem, error) { engine := db.Eloquent.Master() session := engine.NewSession() defer session.Close() - now := time.Now() result := model.TargetItem{} custOrderDao := dal.NewCustOrderDAO(session, user.PlantNr, user.UserId) packDao := jitDal.NewPackOrderDAO(session, user.PlantNr, user.UserId) @@ -1004,13 +962,10 @@ func (impl *CustOrderServiceImplement) CountTarget(user *global.User, dayModel * for _, v := range workLineLi { workLineIds = append(workLineIds, v.WorkLineid) } - today := now.Format(grmi.DateOutFormat) - start := today + " " + "00:00:00" - end := today + " " + "23:59:59" custOrderLi, err := custOrderDao.JoinSelect([]grmi.Predicate{ meta.CustOrder_WorkLineId.NewPredicate(grmi.Equal, workLineId), - meta.CustOrder_PlanStartTime.NewPredicate(grmi.GreaterOrEqual, start), - meta.CustOrder_PlanStartTime.NewPredicate(grmi.LessThen, end), + meta.CustOrder_PlanStartTime.NewPredicate(grmi.GreaterOrEqual, utils.TimeFormat(startDayTime, "yyyy-MM-dd HH:mm:ss")), + meta.CustOrder_PlanStartTime.NewPredicate(grmi.LessThen, utils.TimeFormat(endDayTime, "yyyy-MM-dd HH:mm:ss")), }, []grmi.Field{meta.CustOrder_PlanStartTime}) if err != nil { return result, err @@ -1020,57 +975,16 @@ func (impl *CustOrderServiceImplement) CountTarget(user *global.User, dayModel * result.Target += custOrderData.OrderQty.PlanQty - custOrderData.OrderQty.CancelQty } - todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" - todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation) - //计算当班平均节拍 - switch WorkShift { - case 1: - //查询当班开始和结束时间 - WorkShift1StartTime := todayStartTime.Add(time.Duration(dayModel.S1Beg) * time.Second) - WorkShift1EndTime := todayStartTime.Add(time.Duration(dayModel.S1End) * time.Second) - - startTime := utils.TimeFormat(WorkShift1StartTime, "yyyy-MM-dd HH:mm:ss") - endTime := utils.TimeFormat(WorkShift1EndTime, "yyyy-MM-dd HH:mm:ss") - - packList, err := packDao.SelectUserClosePackOrder(startTime, endTime, workLineIds) - if err != nil { - return result, err - } - result.Current = len(packList) - case 2: - //查询当班开始和结束时间 - - WorkShift2StartTime := todayStartTime.Add(time.Duration(dayModel.S2Beg) * time.Second) - WorkShift2EndTime := todayStartTime.Add(time.Duration(dayModel.S2End) * time.Second) - - startTime := utils.TimeFormat(WorkShift2StartTime, "yyyy-MM-dd HH:mm:ss") - endTime := utils.TimeFormat(WorkShift2EndTime, "yyyy-MM-dd HH:mm:ss") - - packList, err := packDao.SelectUserClosePackOrder(startTime, endTime, workLineIds) - if err != nil { - return result, err - } - result.Current = len(packList) - case 3: - //查询当班开始和结束时间 - - WorkShift3StartTime := todayStartTime.Add(time.Duration(dayModel.S3Beg) * time.Second) - WorkShift3EndTime := todayStartTime.Add(time.Duration(dayModel.S3End) * time.Second) - - startTime := utils.TimeFormat(WorkShift3StartTime, "yyyy-MM-dd HH:mm:ss") - endTime := utils.TimeFormat(WorkShift3EndTime, "yyyy-MM-dd HH:mm:ss") - - packList, err := packDao.SelectUserClosePackOrder(startTime, endTime, workLineIds) - if err != nil { - return result, err - } - result.Current = len(packList) + packList, 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 { + return result, err } + result.Current = len(packList) return result, nil } //计算当班节拍数量 -func (impl *CustOrderServiceImplement) SelectTeamTemPo(user *global.User, dayModel *baseModel.DayModel, jPHPercent float64, num int, startDayTime time.Time, WorkShift int, workLineId string) (TeamTemPoNumber float64, PerTeamTemPoNumber float64, err error) { +func (impl *CustOrderServiceImplement) SelectTeamTemPo(user *global.User, dayModel *baseModel.DayModel, jPHPercent float64, num int, startDayTime time.Time, endDayTime time.Time, WorkShift int, workLineId string, dayStartTime time.Time) (TeamTemPoNumber float64, PerTeamTemPoNumber float64, err error) { engine := db.Eloquent.Master() session := engine.NewSession() defer session.Close() @@ -1087,105 +1001,36 @@ func (impl *CustOrderServiceImplement) SelectTeamTemPo(user *global.User, dayMod for _, v := range workLineLi { workLineIds = append(workLineIds, v.WorkLineid) } - now := time.Now() - todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" - todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation) - - timeModelList := impl.InitDayModelList(dayModel, todayStartTime) - //计算当班平均节拍 - switch WorkShift { - case 1: - //查询当班开始和结束时间 - WorkShift1StartTime := todayStartTime.Add(time.Duration(dayModel.S1Beg) * time.Second) - WorkShift1EndTime := todayStartTime.Add(time.Duration(dayModel.S1End) * time.Second) - - startTime := utils.TimeFormat(WorkShift1StartTime, "yyyy-MM-dd HH:mm:ss") - endTime := utils.TimeFormat(WorkShift1EndTime, "yyyy-MM-dd HH:mm:ss") - - packData, err := packOrderDao.SelectUserClosePackOrder(startTime, endTime, workLineIds) - if err != nil { - return 0, 0, err - } - countPack := len(packData) - - packTimes := impl.GetUsefulTime(WorkShift1StartTime, time.Now(), timeModelList) - - if countPack > 0 { - TeamTemPoNumber = utils.Decimal(float64(packTimes)/float64(countPack), 2) - packHours := float64(packTimes) / float64(3600) - if packHours > 0 { - PerTeamTemPoNumber = utils.Decimal(float64(countPack)*jPHPercent/float64(num)/float64(packHours), 3) - } else { - PerTeamTemPoNumber = 0 - } + //now := time.Now() + //todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" + //todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation) + timeModelList := impl.InitDayModelList(dayModel, dayStartTime) + packData, err := packOrderDao.SelectUserClosePackOrder(utils.TimeFormat(startDayTime, "yyyy-MM-dd HH:mm:ss"), utils.TimeFormat(endDayTime, "yyyy-MM-dd HH:mm:ss"), workLineIds) + if err != nil { + return 0, 0, err + } + countPack := len(packData) + packTimes := impl.GetUsefulTime(startDayTime, time.Now(), timeModelList) + if countPack > 0 { + TeamTemPoNumber = utils.Decimal(float64(packTimes)/float64(countPack), 2) + packHours := float64(packTimes) / float64(3600) + if packHours > 0 { + PerTeamTemPoNumber = utils.Decimal(float64(countPack)*jPHPercent/float64(num)/float64(packHours), 3) } else { - TeamTemPoNumber = 0 - PerTeamTemPoNumber = 0 - } - return TeamTemPoNumber, PerTeamTemPoNumber, nil - case 2: - //查询当班开始和结束时间 - - WorkShift2StartTime := todayStartTime.Add(time.Duration(dayModel.S2Beg) * time.Second) - WorkShift2EndTime := todayStartTime.Add(time.Duration(dayModel.S2End) * time.Second) - - startTime := utils.TimeFormat(WorkShift2StartTime, "yyyy-MM-dd HH:mm:ss") - endTime := utils.TimeFormat(WorkShift2EndTime, "yyyy-MM-dd HH:mm:ss") - - packData, err := packOrderDao.SelectUserClosePackOrder(startTime, endTime, workLineIds) - if err != nil { - return 0, 0, err - } - countPack := len(packData) - packTimes := impl.GetUsefulTime(WorkShift2StartTime, time.Now(), timeModelList) - if countPack > 0 { - TeamTemPoNumber = utils.Decimal(float64(packTimes)/float64(countPack), 2) - packHours := float64(packTimes) / float64(3600) - if packHours > 0 { - PerTeamTemPoNumber = utils.Decimal(float64(countPack)*jPHPercent/float64(num)/float64(packHours), 3) - } else { - PerTeamTemPoNumber = 0 - } - } else { - TeamTemPoNumber = 0 - PerTeamTemPoNumber = 0 - } - return TeamTemPoNumber, PerTeamTemPoNumber, nil - case 3: - //查询当班开始和结束时间 - - WorkShift3StartTime := todayStartTime.Add(time.Duration(dayModel.S3Beg) * time.Second) - WorkShift3EndTime := todayStartTime.Add(time.Duration(dayModel.S3End) * time.Second) - - startTime := utils.TimeFormat(WorkShift3StartTime, "yyyy-MM-dd HH:mm:ss") - endTime := utils.TimeFormat(WorkShift3EndTime, "yyyy-MM-dd HH:mm:ss") - - packData, err := packOrderDao.SelectUserClosePackOrder(startTime, endTime, workLineIds) - if err != nil { - return 0, 0, err - } - countPack := len(packData) - packTimes := impl.GetUsefulTime(WorkShift3StartTime, time.Now(), timeModelList) - if countPack > 0 { - TeamTemPoNumber = utils.Decimal(float64(packTimes)/float64(countPack), 2) - packHours := float64(packTimes) / float64(3600) - if packHours > 0 { - PerTeamTemPoNumber = utils.Decimal(float64(countPack)*jPHPercent/float64(num)/float64(packHours), 3) - } else { - PerTeamTemPoNumber = 0 - } - } else { - TeamTemPoNumber = 0 PerTeamTemPoNumber = 0 } - return TeamTemPoNumber, PerTeamTemPoNumber, nil + } else { + TeamTemPoNumber = 0 + PerTeamTemPoNumber = 0 } + return TeamTemPoNumber, PerTeamTemPoNumber, nil + return 0, 0, nil } //图例1 -func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *baseModel.DayModel, workLineId string) (result model.CutLine1, err error) { +func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *baseModel.DayModel, workLineId string, startTime, endTime, dayStartTime time.Time) (result model.CutLine1, err error) { engine := db.Eloquent.Master() session := engine.NewSession() defer session.Close() @@ -1196,11 +1041,11 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *b productFamilyMap := make(map[string]*meModel.ProductFamily) productFamilyRelateMap := make(map[string]map[string]interface{}) productFamilyMeterMap := make(map[string]float64) - now := time.Now() + //now := time.Now() //now, _ := time.ParseInLocation(grmi.DateTimeOutFormat, "2022-05-18 23:00:00", utils.TimezoneLocation) - endTime := now.Format(grmi.DateOutFormat) + " 23:59:59" - todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" - todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation) + //endTime := now.Format(grmi.DateOutFormat) + " 23:59:59" + //todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" + //todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation) // 查询正在正在生产的客户订单 custOrderLi, err := custOrderDao.SelectRunningCustOrder(workLineId) @@ -1237,7 +1082,7 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *b productFamilyRelateMap[custOrder.ProductFamilyId][product.ProductId] = nil } } - timeModelList := impl.InitDayModelList(dayModel, todayStartTime) + timeModelList := impl.InitDayModelList(dayModel, dayStartTime) workLineDao := baseDal.NewWorkLineDAO(session, user.PlantNr, user.UserId) workLineLi, err := workLineDao.Select([]grmi.Predicate{baseMeta.WorkLine_GroupLineId.NewPredicate(grmi.Equal, workLineId)}, nil) if err != nil { @@ -1250,7 +1095,7 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *b for _, v := range workLineLi { workLineIds = append(workLineIds, v.WorkLineid) } - packOrderLi, err := packOrderDao.SelectClosedPackOrder(todayStart, endTime, workLineIds) + packOrderLi, err := packOrderDao.SelectClosedPackOrder(startTime.Format(grmi.DateTimeOutFormat), endTime.Format(grmi.DateTimeOutFormat), workLineIds) if err != nil { return result, grmi.NewBusinessError("查询包装单数据失败") } @@ -1361,14 +1206,14 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *b productDataLi = append(productDataLi, data) } //impl.QuickSortProductData(productDataLi) - currentTime := todayStartTime.Add(time.Hour * time.Duration(hour)) + currentTime := dayStartTime.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 = todayStartTime.Add(time.Hour * time.Duration(hour)) + currentTime = dayStartTime.Add(time.Hour * time.Duration(hour)) for _, productFamilyProductData := range productDataLi { usedTime := impl.GetUsefulTime(currentTime, productFamilyProductData.LastDoneTime, timeModelList) @@ -1445,7 +1290,7 @@ func (impl *CustOrderServiceImplement) GetUsefulTime(start, end time.Time, timeL } //图例3 -func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHours []string, dayModel *baseModel.DayModel, jPHPercent float64, startDayTime time.Time, endDayTime time.Time, timeBeat float64, attendancePersonNum int, workLineId string) (model.PerDashboardData, error) { +func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHours []string, dayModel *baseModel.DayModel, jPHPercent float64, startDayTime time.Time, endDayTime time.Time, timeBeat float64, attendancePersonNum int, workLineId string, dayStartTime time.Time) (model.PerDashboardData, error) { engine := db.Eloquent.Master() session := engine.NewSession() defer session.Close() @@ -1454,11 +1299,9 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou packOrderDao := jitDal.NewPackOrderDAO(session, user.PlantNr, user.UserId) 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" - todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation) + //now := time.Now() + //todayStart := now.Format(grmi.DateOutFormat) + " 00:00:00" + //todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation) packDao := jitDal.NewPackOrderDAO(session, user.PlantNr, user.UserId) //图例003 DashboardData3 := model.PerDashboardData{} @@ -1476,9 +1319,9 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou workLineIds = append(workLineIds, v.WorkLineid) } - timeModelList := impl.InitDayModelList(dayModel, todayStartTime) + timeModelList := impl.InitDayModelList(dayModel, dayStartTime) - packOrderLi, err := packOrderDao.SelectClosedPackOrder(todayStart, endTime, workLineIds) + packOrderLi, err := packOrderDao.SelectClosedPackOrder(utils.TimeFormat(startDayTime, ""), utils.TimeFormat(endDayTime, ""), workLineIds) if err != nil { return DashboardData3, grmi.NewBusinessError("查询包装单数据失败") } @@ -1571,9 +1414,15 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou //定义动态JPH jphMap := make(map[string]float64) - - for hour := 0; hour < 24; hour++ { - key := utils.TimeFormat(todayStartTime.Add(time.Duration(hour)*time.Hour), "yyyy-MM-dd HH:00") + hours, err := utils.GetHoursData(startDayTime, endDayTime) + if err != nil { + return DashboardData3, err + } + if len(hours) == 0 { + return DashboardData3, err + } + for hour := 0; hour < len(hours); hour++ { + key := utils.TimeFormat(dayStartTime.Add(time.Duration(hour)*time.Hour), "yyyy-MM-dd HH:00") hourData, exist := displayHourProductMap[hour] if !exist { continue @@ -1583,14 +1432,14 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou for _, data := range hourData { productDataLi = append(productDataLi, data) } - currentTime := todayStartTime.Add(time.Hour * time.Duration(hour)) + currentTime := dayStartTime.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 = todayStartTime.Add(time.Hour * time.Duration(hour)) + currentTime = dayStartTime.Add(time.Hour * time.Duration(hour)) for _, productFamilyProductData := range productDataLi { usedTime := impl.GetUsefulTime(currentTime, productFamilyProductData.LastDoneTime, timeModelList) currentTime = productFamilyProductData.LastDoneTime @@ -1653,7 +1502,10 @@ func (impl *CustOrderServiceImplement) SelectPic3(user *global.User, DayModelHou } DashboardData3.DashboardData2 = append(DashboardData3.DashboardData2, two) } + glog.InfoExtln("DashboardData3", "DashboardData3.CompleteNumber:", DashboardData3.CompleteNumber) + glog.InfoExtln("DashboardData3", "jPHPercent:", jPHPercent) DashboardData3.CompleteNumber = utils.ValueToInt(utils.ValueToFloat(DashboardData3.CompleteNumber, 0.0)*jPHPercent, 0) + glog.InfoExtln("DashboardData3", "DashboardData3.CompleteNumber2:", DashboardData3.CompleteNumber) return DashboardData3, nil }