|
|
@ -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:]) |
|
|
|
} |