#189 修改dashboard的逻辑

Merged
weichenglei merged 2 commits from feature_om into develop 2 years ago
  1. +4
    -3
      dao/om/implments/SerialOrder.dao.impl.go
  2. +1
    -1
      dao/om/implments/SerialOrderPOLst.dao.impl.go
  3. +21
    -0
      dao/pln/CustOrder.dao.go
  4. +47
    -40
      dao/pln/implments/CustOrder.dao.impl.go
  5. +11
    -3
      models/pln/pln.go
  6. +233
    -145
      services/pln/implments/CustOrder.service.impl.go

+ 4
- 3
dao/om/implments/SerialOrder.dao.impl.go View File

@ -4,8 +4,8 @@ package implments
import (
"LAPP_ACURA_MOM_BACKEND/grmi"
meta "LAPP_ACURA_MOM_BACKEND/meta/om"
meMeta "LAPP_ACURA_MOM_BACKEND/meta/me"
meta "LAPP_ACURA_MOM_BACKEND/meta/om"
common "LAPP_ACURA_MOM_BACKEND/models/base"
model "LAPP_ACURA_MOM_BACKEND/models/om"
"fmt"
@ -730,10 +730,11 @@ func (impl *SerialOrderDAOImplement) SelectByOriginSerialOrderId(serialOrderId s
*
******************************************************************************/
func (impl *SerialOrderDAOImplement) SelectByCustOrderIdForDashboard(custOrderId, start, end string) ([]model.SerialOrder, error) {
parameters := []interface{}{impl.plantNr, custOrderId, start, end, common.QualityCheck_STATUS_OK, common.QualityCheck_STATUS_FAIL}
where := fmt.Sprintf("%s = ? and %s = ? and %s >= ? and %s <= ? and (%s = ? or %s = ?) ",
parameters := []interface{}{impl.plantNr, custOrderId, common.ODER_TYPE_SEQ, start, end, common.QualityCheck_STATUS_OK, common.QualityCheck_STATUS_FAIL}
where := fmt.Sprintf("%s = ? and %s = ? and %s = ? and %s >= ? and %s <= ? and (%s = ? or %s = ?) ",
meta.SerialOrder_PlantNr.ColumnName,
meta.SerialOrder_CustOrderId.ColumnName,
meta.SerialOrder_OrderType.ColumnName,
meta.SerialOrder_ActStartTime.ColumnName,
meta.SerialOrder_ActEndTime.ColumnName,
meta.SerialOrder_QualityCheck.ColumnName,


+ 1
- 1
dao/om/implments/SerialOrderPOLst.dao.impl.go View File

@ -400,6 +400,6 @@ func (impl *SerialOrderPOLstDAOImplement) SelectByOrderLi(serialOrderIdLi []inte
result := make([]model.SerialOrderPOWithProcess, 0)
err := impl.session.Table(impl.meta.TableName).Join("LEFT", baseMeta.Process.TableName, poCondition).
Join("LEFT", baseMeta.WorkLineProcessLst.TableName, wpCondition).
Where(where, parameters...).In(meta.SerialOrderPOLst_SerialOrderId.ColumnName, serialOrderIdLi).OrderBy(baseMeta.WorkLineProcessLst_Pos.ColumnName).Find(&result)
Where(where, parameters...).In(meta.SerialOrderPOLst_SerialOrderId.ColumnName, serialOrderIdLi).OrderBy(baseMeta.WorkLineProcessLst_Pos.SortColumnName).OrderBy(meta.SerialOrderPOLst_CreateTime.SortColumnName).Find(&result)
return result, err
}

+ 21
- 0
dao/pln/CustOrder.dao.go View File

@ -433,6 +433,27 @@ type CustOrderDAO interface {
*
******************************************************************************/
SelectCurrentDayCustOrder(start, end string) ([]model.CustOrder, error)
/******************************************************************************
*
* @Function Name : Select
*-----------------------------------------------------------------------------
*
* @Description : 按条件查询CustOrder
*
* @Function Parameters : 查询条件
*
* @Function Parameters : 排序字段
*
* @Return Value : 查询结果
*
* @Return Value : 执行时发生的错误
*
* @Author : zhangxin
*
* @Date : 2022-04-03
*
******************************************************************************/
JoinSelect(predicates []grmi.Predicate, orderByFields []grmi.Field) ([]model.CustOrder, error)
}
/******************************************************************************


+ 47
- 40
dao/pln/implments/CustOrder.dao.impl.go View File

@ -726,46 +726,53 @@ func (impl *CustOrderDAOImplement) PageSelect(custOrderId string, workLineId str
* @Reference LAPP_ACURA_MOM_BACKEND/dao/pln/CustOrderDAO.JoinSelect
*
******************************************************************************/
//func (impl *CustOrderDAOImplement) JoinSelect(predicates []grmi.Predicate, orderByFields []grmi.Field) ([]model.CustOrder, error) {
//
// parameters := []interface{}{impl.plantNr}
// where := fmt.Sprintf("%s = ?", meta.CustOrder_PlantNr.ColumnName)
// statusCondition := fmt.Sprintf("%s = %s and %s = %s",
// meta.CustOrder_PlantNr.ColumnName,
// meta.CustOrderStatus_PlantNr.ColumnName,
// meta.CustOrder_CustOrderId.ColumnName,
// meta.CustOrderStatus_CustOrderId.ColumnName)
// qtyCondition := fmt.Sprintf("%s = %s and %s = %s",
// meta.CustOrder_PlantNr.ColumnName,
// meta.CustOrderQty_PlantNr.ColumnName,
// meta.CustOrder_CustOrderId.ColumnName,
// meta.CustOrderQty_CustOrderId.ColumnName)
//
// session := impl.session.Table(impl.meta.TableName)
// if predicates != nil {
// for _, predicate := range predicates {
// where += predicate.Build()
// parameters = append(parameters, predicate.Values...)
// }
// session = session.Where(where, parameters...)
// } else {
// session = session.Where(where, parameters...)
// }
//
// session = session.OrderBy(meta.CustOrder_PlantNr.ColumnName)
// if orderByFields != nil {
// for _, field := range orderByFields {
// session = session.OrderBy(field.ColumnName)
// }
// }
//
// data := make([]model.CustOrder, 0, 10)
// err := session.Find(&data)
// if err != nil {
// return nil, grmi.NewDataBaseError(err)
// }
// return data, nil
//}
func (impl *CustOrderDAOImplement) JoinSelect(predicates []grmi.Predicate, orderByFields []grmi.Field) ([]model.CustOrder, error) {
parameters := []interface{}{impl.plantNr}
where := fmt.Sprintf("%s = ?", meta.CustOrder_PlantNr.ColumnName)
statusCondition := fmt.Sprintf("%s = %s and %s = %s",
meta.CustOrder_PlantNr.ColumnName,
meta.CustOrderStatus_PlantNr.ColumnName,
meta.CustOrder_CustOrderId.ColumnName,
meta.CustOrderStatus_CustOrderId.ColumnName)
qtyCondition := fmt.Sprintf("%s = %s and %s = %s",
meta.CustOrder_PlantNr.ColumnName,
meta.CustOrderQty_PlantNr.ColumnName,
meta.CustOrder_CustOrderId.ColumnName,
meta.CustOrderQty_CustOrderId.ColumnName)
session := impl.session.Table(impl.meta.TableName).Join("INNER", meta.CustOrderStatus.TableName, statusCondition).Join("INNER", meta.CustOrderQty.TableName, qtyCondition)
if predicates != nil {
for _, predicate := range predicates {
where += predicate.Build()
parameters = append(parameters, predicate.Values...)
}
session = session.Where(where, parameters...)
} else {
session = session.Where(where, parameters...)
}
session = session.OrderBy(meta.CustOrder_PlantNr.ColumnName)
if orderByFields != nil {
for _, field := range orderByFields {
session = session.OrderBy(field.ColumnName)
}
}
data := make([]model.CustOrderData, 0, 10)
err := session.Find(&data)
if err != nil {
return nil, grmi.NewDataBaseError(err)
}
result := make([]model.CustOrder, 0, len(data))
for _, custOrderData := range data {
custOrder := custOrderData.CustOrder
custOrder.OrderStatus = custOrderData.CustOrderStatus
custOrder.OrderQty = custOrderData.CustOrderQty
result = append(result, custOrder)
}
return result, nil
}
func (impl *CustOrderDAOImplement) SelectCustOrderByPlan(start, end string) ([]model.CustOrderData, error) {
parameters := []interface{}{impl.plantNr, start, end, start, start}


+ 11
- 3
models/pln/pln.go View File

@ -56,9 +56,17 @@ type ProductFamilyProduce struct {
}
type CutLine1 struct {
TimeLi []string `json:"timeLi"`
ProductFamilyMeter map[string]int `json:"productFamilyMeter"`
ProduceData []ProductFamilyProduce `json:"produceData"`
TimeLi []string `json:"timeLi"`
Standard float64 `json:"standard"`
ProductFamilyMeter int `json:"productFamilyMeter"`
ProduceData []float64 `json:"produceData"`
}
// 派生每个小时产量map
type HourProductData struct {
ProductFamilyId string
LastDoneTime time.Time
Qty int
}
//Dashboard数据展示


+ 233
- 145
services/pln/implments/CustOrder.service.impl.go View File

@ -9,6 +9,7 @@ import (
meDal "LAPP_ACURA_MOM_BACKEND/dao/me"
omDal "LAPP_ACURA_MOM_BACKEND/dao/om"
dal "LAPP_ACURA_MOM_BACKEND/dao/pln"
qmDal "LAPP_ACURA_MOM_BACKEND/dao/qm"
"LAPP_ACURA_MOM_BACKEND/db"
"LAPP_ACURA_MOM_BACKEND/global"
"LAPP_ACURA_MOM_BACKEND/grmi"
@ -17,6 +18,7 @@ import (
jitMeta "LAPP_ACURA_MOM_BACKEND/meta/jit"
omMeta "LAPP_ACURA_MOM_BACKEND/meta/om"
meta "LAPP_ACURA_MOM_BACKEND/meta/pln"
qmMeta "LAPP_ACURA_MOM_BACKEND/meta/qm"
baseModel "LAPP_ACURA_MOM_BACKEND/models/base"
jitModel "LAPP_ACURA_MOM_BACKEND/models/jit"
meModel "LAPP_ACURA_MOM_BACKEND/models/me"
@ -26,12 +28,8 @@ import (
"LAPP_ACURA_MOM_BACKEND/utils"
"container/list"
"errors"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize/v2"
uuid "github.com/iris-contrib/go.uuid"
"math"
//"math"
"strconv"
"strings"
"sync"
@ -2448,14 +2446,13 @@ func (impl *CustOrderServiceImplement) Dashboard(user *global.User) (interface{}
if err != nil {
return nil, err
}
DashboardData := model.DashboardPic{}
var err1, err2, err3, err4, err5, err6 error
var wg sync.WaitGroup
wg.Add(6)
//图例001
go func() {
DashboardData.DashboardDataPic1, err1 = impl.SelectPic1(user)
DashboardData.DashboardDataPic1, err1 = impl.SelectPic1(user, dayModel)
wg.Done() // 操作完成,减少一个计数
}()
@ -2794,28 +2791,80 @@ func (impl *CustOrderServiceImplement) InitDayModelList(dayModel *baseModel.DayM
return dayModelList
}
// SelectDefectNumber dashboard右上角 查询缺陷数据
func (impl *CustOrderServiceImplement) SelectDefectNumber(user *global.User, days int) ([]model.DefectItem, error) {
result := make([]model.DefectItem, 0, days)
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
//defectRecordDao := qmDal.NewDefectRecordDAO(session, user.PlantNr, user.UserId)
//repairInfoDao := baseDal.NewRepairInfoDAO(session, user.UserId)
defectRecordDao := qmDal.NewDefectRecordDAO(session, user.PlantNr, user.UserId)
repairInfoDao := baseDal.NewRepairInfoDAO(session, user.UserId)
custOrderDao := dal.NewCustOrderDAO(session, user.PlantNr, user.UserId)
productFamilyRelateDao := meDal.NewProductFamilyRelateDAO(session, user.PlantNr, user.UserId)
productFamilyMap := make(map[string]int)
now := time.Now()
statusRecDao := omDal.NewSerialOrderStatusRecLstDAO(session, user.PlantNr, user.UserId)
for i := 0; i < days; i++ {
var defectItem model.DefectItem
day := now.AddDate(0, 0, -1*i).Format(grmi.DateOutFormat)
defectItem.Date = day
start := day + " " + "00:00:00"
end := day + " " + "23:59:59"
count, err := statusRecDao.CountDefect(start, end)
defectRecordLi, err := defectRecordDao.Select([]grmi.Predicate{
qmMeta.DefectRecord_CreateTime.NewPredicate(grmi.GreaterOrEqual, start),
qmMeta.DefectRecord_CreateTime.NewPredicate(grmi.LessOrEqual, end),
}, []grmi.Field{qmMeta.DefectRecord_SerialOrderId})
if err != nil {
return nil, err
return nil, grmi.NewBusinessError("查询缺陷记录失败,错误:" + err.Error())
}
serialOrderMap := make(map[string]interface{})
for _, defectRecord := range defectRecordLi {
_, exist := serialOrderMap[defectRecord.SerialOrderId]
if !exist {
serialOrderMap[defectRecord.SerialOrderId] = nil
}
}
repairInfoLi, err := repairInfoDao.Select([]grmi.Predicate{
baseMeta.RepairInfo_CreateTime.NewPredicate(grmi.GreaterOrEqual, start),
baseMeta.RepairInfo_CreateTime.NewPredicate(grmi.LessOrEqual, end),
}, []grmi.Field{baseMeta.RepairInfo_SerialOrderId})
if err != nil {
return nil, grmi.NewBusinessError("查询返修记录失败, 错误:" + err.Error())
}
for _, repairInfo := range repairInfoLi {
_, exist := serialOrderMap[repairInfo.SerialOrderId]
if !exist {
serialOrderMap[repairInfo.SerialOrderId] = nil
}
}
defectItem.Number = count
defectNumber := len(serialOrderMap)
custOrderLi, err := custOrderDao.JoinSelect([]grmi.Predicate{
meta.CustOrder_PlanStartTime.NewPredicate(grmi.GreaterOrEqual, start),
meta.CustOrder_PlanStartTime.NewPredicate(grmi.LessThen, end),
}, []grmi.Field{meta.CustOrder_PlanStartTime})
if err != nil {
return nil, grmi.NewBusinessError("查询客户订单失败, 错误:" + err.Error())
}
var planQty int
for _, custOrder := range custOrderLi {
packNum, exist := productFamilyMap[custOrder.ProductFamilyId]
if !exist {
productLi, err := productFamilyRelateDao.SelectProductByFamilyId(custOrder.ProjectId, custOrder.ProductFamilyId)
if err != nil {
return nil, grmi.NewBusinessError("查询派生数据失败, 错误:" + err.Error())
}
packNum = len(productLi)
productFamilyMap[custOrder.ProductFamilyId] = packNum
}
planQty += packNum * (custOrder.OrderQty.PlanQty - custOrder.OrderQty.CancelQty)
}
var percent int64
if planQty == 0 {
percent = 0
} else {
percent = int64(float64(defectNumber) / float64(planQty) * 1000000)
}
defectItem.Number = percent
defectItem.Date = day
result = append(result, defectItem)
//defectRecordDao.Select([]grmi.Predicate)
}
return result, nil
}
@ -2970,17 +3019,21 @@ func (impl *CustOrderServiceImplement) SelectTeamTemPo(user *global.User, dayMod
}
//图例1
func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, ) (result *model.CutLine1, err error) {
func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, dayModel *baseModel.DayModel) (result *model.CutLine1, err error) {
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
custOrderDao := dal.NewCustOrderDAO(session, user.PlantNr, user.UserId)
custOrderStatusDao := dal.NewCustOrderStatusDAO(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-03-20 23:00:00", utils.TimezoneLocation)
endTime := now.Format(grmi.DateTimeOutFormat)
now, _ := time.ParseInLocation(grmi.DateTimeOutFormat, "2022-03-30 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())
todayStartTime, _ := time.ParseInLocation(grmi.DateTimeOutFormat, todayStart, utils.TimezoneLocation)
@ -2992,6 +3045,50 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, ) (result *
dateTimeLi = append(dateTimeLi, num)
num++
}
timeModelList := impl.InitDayModelList(dayModel, todayStartTime)
// 查询正在正在生产的客户订单
custOrderStatusLi, err := custOrderStatusDao.Select([]grmi.Predicate{meta.CustOrderStatus_Status.NewPredicate(grmi.Equal, baseModel.WO_STATUS_RUNNING)}, []grmi.Field{meta.CustOrderStatus_LastModify})
if err != nil {
return nil, grmi.NewBusinessError("查询客户订单状态数据失败, 错误:" + err.Error())
}
var currentMeter int
if len(custOrderStatusLi) == 0 {
currentMeter = 0
} else {
currentCustOrderId := custOrderStatusLi[len(custOrderStatusLi)-1].CustOrderId
custOrder, err := custOrderDao.SelectOne(currentCustOrderId)
if err != nil {
return nil, grmi.NewBusinessError("查询客户订单数据失败, 错误:" + err.Error())
}
if custOrder == nil {
return nil, grmi.NewBusinessError("客户订单数据不存在, 订单条码:" + currentCustOrderId)
}
productFamily, err := productFamilyDao.SelectOne(custOrder.ProductFamilyId)
if err != nil {
return nil, grmi.NewBusinessError("查询派生数据失败, 错误:" + err.Error())
}
if productFamily == nil {
return nil, grmi.NewBusinessError("客户订单派生不存在, 派生ID:" + custOrder.ProductFamilyId)
}
if productFamily.Jph == 0 {
return nil, grmi.NewBusinessError("派生JPH为0 派生ID:" + custOrder.ProductFamilyId)
}
currentMeter = int(float64(3600) / productFamily.Jph)
productFamilyMeterMap[custOrder.ProductFamilyId] = float64(3600) / productFamily.Jph
productFamilyMap[custOrder.ProductFamilyId] = productFamily
productLi, err := productFamilyRelateDao.SelectProductByFamilyId(custOrder.ProjectId, custOrder.ProductFamilyId)
if err != nil {
return nil, grmi.NewBusinessError("查询派生下总成数据失败, 错误:" + err.Error())
}
if len(productLi) == 0 {
return nil, 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
@ -2999,15 +3096,11 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, ) (result *
if err != nil {
return nil, grmi.NewBusinessError("查询客户订单失败, 错误:" + err.Error())
}
productFamilyMap := make(map[string]*meModel.ProductFamily)
productFamilyRelateMap := make(map[string]int)
productFamilyMeterMap := make(map[string]int)
// 派生每个小时产量map
productFamilyAccomplishMap := make(map[string]map[int]int)
productFamilyAccomplishMap := make(map[int]map[string]model.HourProductData)
for _, custOrderData := range custOrderDataLi {
productFamilyId := custOrderData.CustOrder.ProductFamilyId
productFamily, exist := productFamilyMap[productFamilyId]
var meter int
if !exist {
productFamily, err = productFamilyDao.SelectOne(productFamilyId)
if err != nil {
@ -3016,6 +3109,9 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, ) (result *
if productFamily == nil {
return nil, grmi.NewBusinessError("客户订单中派生不存在, 派生Id:" + productFamilyId + ", 客户订单Id:" + custOrderData.CustOrder.CustOrderId)
}
if productFamily.Jph == 0 {
return nil, grmi.NewBusinessError("派生JPH为0 派生ID:" + productFamilyId)
}
productLi, err := productFamilyRelateDao.SelectProductByFamilyId(custOrderData.CustOrder.ProjectId, productFamilyId)
if err != nil {
return nil, grmi.NewBusinessError("查询派生下总成数据失败, 错误:" + err.Error())
@ -3023,12 +3119,12 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, ) (result *
if len(productLi) == 0 {
return nil, grmi.NewBusinessError("派生下未关联需要生产的座椅总成, 派生ID:" + productFamilyId)
}
productFamilyRelateMap[productFamilyId] = len(productLi)
productFamilyRelateMap[productFamilyId] = make(map[string]interface{}, len(productLi))
for _, product := range productLi {
productFamilyRelateMap[productFamilyId][product.ProductId] = nil
}
productFamilyMap[productFamilyId] = productFamily
meter = int(math.Ceil(3600 / productFamily.Jph))
productFamilyMeterMap[productFamilyId] = meter
} else {
meter = productFamilyMeterMap[productFamilyId]
productFamilyMeterMap[productFamilyId] = float64(3600) / productFamily.Jph
}
// 查询客户订单下的工单
serialOrderDataLi, err := serialOrderDao.SelectByCustOrderIdForDashboard(custOrderData.CustOrder.CustOrderId, todayStart, endTime)
@ -3041,13 +3137,28 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, ) (result *
for _, serialOrder := range serialOrderDataLi {
_, exist = syncKeyMap[serialOrder.SyncKey]
if !exist {
syncKeyMap[serialOrder.SyncKey] = make([]omModel.SerialOrder, 0, productFamilyRelateMap[productFamilyId])
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) == productFamilyRelateMap[productFamilyId] {
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) {
@ -3057,135 +3168,89 @@ func (impl *CustOrderServiceImplement) SelectPic1(user *global.User, ) (result *
syncKeyAccomplishTimeMap[syncKey] = accomplishTime
}
}
// 当前派生下记录每个小时完成的台套数量
everyHourAccomplishQty, exist := productFamilyAccomplishMap[productFamilyId]
if !exist {
productFamilyAccomplishMap[productFamilyId] = make(map[int]int)
everyHourAccomplishQty = productFamilyAccomplishMap[productFamilyId]
}
// 记录每个小时完成的数量和时间
for _, accomplishTime := range syncKeyAccomplishTimeMap {
hour := accomplishTime.Hour()
_, exist = everyHourAccomplishQty[hour]
hourProductMap, exist := productFamilyAccomplishMap[hour]
if !exist {
everyHourAccomplishQty[hour] = 1
} else {
everyHourAccomplishQty[hour] += 1
productFamilyAccomplishMap[hour] = make(map[string]model.HourProductData)
hourProductMap = productFamilyAccomplishMap[hour]
}
}
}
deleteKeyLi := make([]string, 0)
for productFamilyId, _ := range productFamilyMeterMap {
_, exist := productFamilyAccomplishMap[productFamilyId]
if !exist {
deleteKeyLi = append(deleteKeyLi, productFamilyId)
}
}
for _, deleteKey := range deleteKeyLi {
delete(productFamilyMeterMap, deleteKey)
}
result = &model.CutLine1{
TimeLi: make([]string, 0, now.Hour()),
ProductFamilyMeter: productFamilyMeterMap,
}
for _, num = range dateTimeLi {
result.TimeLi = append(result.TimeLi, strconv.Itoa(num)+"时")
}
for productFamilyId, accomplishTimeMap := range productFamilyAccomplishMap {
percentData := model.ProductFamilyProduce{
ProductFamilyId: productFamilyId,
}
for _, num = range dateTimeLi {
qty, exist := accomplishTimeMap[num]
if exist {
meter := productFamilyMeterMap[productFamilyId]
percent := (float64(3600 / qty)) / float64(meter) / 100
percentData.PercentLi = append(percentData.PercentLi, fmt.Sprintf("%.2f", percent))
productFamilyData, exist := hourProductMap[productFamilyId]
if !exist {
hourProductMap[productFamilyId] = model.HourProductData{
ProductFamilyId: productFamilyId,
Qty: 1,
LastDoneTime: accomplishTime,
}
} else {
percentData.PercentLi = append(percentData.PercentLi, "0.00")
productFamilyData.Qty++
if productFamilyData.LastDoneTime.Before(accomplishTime) {
productFamilyData.LastDoneTime = accomplishTime
}
hourProductMap[productFamilyId] = productFamilyData
}
productFamilyAccomplishMap[hour] = hourProductMap
}
result.ProduceData = append(result.ProduceData, percentData)
}
displayIndexLi := make([]int, 0)
for index, _ := range dateTimeLi {
var zeroSign = true
for _, productData := range result.ProduceData {
if productData.PercentLi[index] != "0.00" {
zeroSign = false
break
}
}
if !zeroSign {
displayIndexLi = append(displayIndexLi, index)
}
displayHourLi := make([]string, 0, len(productFamilyAccomplishMap))
for hour, _ := range productFamilyAccomplishMap {
displayHourLi = append(displayHourLi, strconv.Itoa(hour)+"时")
}
displayTimeLi := make([]string, 0)
displayProductData := make([]model.ProductFamilyProduce, 0, len(result.ProduceData))
for _, productData := range result.ProduceData {
displayProductData = append(displayProductData, model.ProductFamilyProduce{
ProductFamilyId: productData.ProductFamilyId,
})
result = &model.CutLine1{
TimeLi: displayHourLi,
Standard: 1.0,
ProductFamilyMeter: currentMeter,
ProduceData: make([]float64, 0, len(displayHourLi)),
}
for _, index := range displayIndexLi {
displayTimeLi = append(displayTimeLi, result.TimeLi[index])
for productIndex, productData := range result.ProduceData {
displayProductData[productIndex].PercentLi = append(displayProductData[productIndex].PercentLi, productData.PercentLi[index])
for hour := 0; hour < 24; hour++ {
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 := todayStartTime.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))
for _, productFamilyProductData := range productDataLi {
usedTime := impl.GetUsefulTime(currentTime, productFamilyProductData.LastDoneTime, timeModelList)
currentTime = productFamilyProductData.LastDoneTime
meter := productFamilyMeterMap[productFamilyProductData.ProductFamilyId]
percent := meter / (float64(usedTime) / float64(productFamilyProductData.Qty)) * (float64(usedTime) / float64(hourAllUsedTime))
hourPercent += percent
}
result.ProduceData = append(result.ProduceData, hourPercent)
}
result.TimeLi = displayTimeLi
result.ProduceData = displayProductData
return result, nil
}
//packDao := jitDal.NewPackOrderDAO(session, user.PlantNr, user.UserId)
//
////图例001
////查询当天所有的包装单情况
//jitData, err := packDao.Select([]grmi.Predicate{
// jitMeta.PackOrder_OpenTime.NewPredicate(grmi.GreaterOrEqual, startDayTime),
// jitMeta.PackOrder_OpenTime.NewPredicate(grmi.LessThen, endDayTime),
// jitMeta.PackOrder_PackTypeId.NewPredicate(grmi.Equal, jitModel.PACK_TYPE_STD),
//}, nil)
//if err != nil {
// return nil, err
//}
//jitMap := make(map[string]int)
//
//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")
// }
//
// _, ok := jitMap[key]
// if ok {
// jitMap[key] += 1
// } else {
// jitMap[key] = 1
// }
//}
//DashboardData1 := make([]model.DashboardData, 0)
//for _, v := range DayModelHours {
// key := v
// val, ok := jitMap[key]
// one := model.DashboardData{}
// one.Date = v
// if ok {
// one.Lable = val
// } else {
// one.Lable = 0
// }
// one.Val = utils.Decimal(float64(one.Lable)/(3600/float64(timeBeat))*100, 2)
// DashboardData1 = append(DashboardData1, one)
//}
//return DashboardData1, nil
func (impl *CustOrderServiceImplement) GetUsefulTime(start, end time.Time, timeLine *list.List) int {
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())
}
}
return duration
}
//图例3
@ -4018,3 +4083,26 @@ func (impl *CustOrderServiceImplement) QuickSort(values []string) {
impl.QuickSort(values[:head])
impl.QuickSort(values[head+1:])
}
func (impl *CustOrderServiceImplement) QuickSortProductData(values []model.HourProductData) {
if len(values) <= 1 {
return
}
mid, i := values[0], 1
midTime := mid.LastDoneTime
head, tail := 0, len(values)-1
for head < tail {
iTime := values[i].LastDoneTime
if iTime.Before(midTime) {
values[i], values[tail] = values[tail], values[i]
tail--
} else {
values[i], values[head] = values[head], values[i]
head++
i++
}
}
values[head] = mid
impl.QuickSortProductData(values[:head])
impl.QuickSortProductData(values[head+1:])
}

Loading…
Cancel
Save