From ed8686df2575726f4b8bda5f699c31d39355cb80 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 21 Feb 2024 15:59:31 +0800 Subject: [PATCH] update --- app/admin/svc/svc_data_statisstics.go | 81 ++++++++++----------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/app/admin/svc/svc_data_statisstics.go b/app/admin/svc/svc_data_statisstics.go index c14838c..57d8dbc 100644 --- a/app/admin/svc/svc_data_statisstics.go +++ b/app/admin/svc/svc_data_statisstics.go @@ -1968,6 +1968,26 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD return } + var ordNoArr, mealKindListArr []string + for _, v := range m { + ordNoArr = append(ordNoArr, v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo) + } + var nativeSql = "SELECT COUNT(*) AS total, kind , ord_no FROM `central_kitchen_for_school_user_with_day` WHERE `ord_no` IN (%s) AND (state !=%d) AND (state !=%d) AND (DATE >= '%s') AND (DATE <= '%s') AND `kind` IN (%s) GROUP BY `ord_no`, `kind`" + for _, v := range req.MealKindList { + mealKindListArr = append(mealKindListArr, utils.IntToStr(v)) + } + sDate, _ := time.ParseInLocation("2006-01-02 15:04:05", req.StartDate, time.Local) + eDate, _ := time.ParseInLocation("2006-01-02 15:04:05", req.EndDate, time.Local) + nativeSql = fmt.Sprintf(nativeSql, strings.Join(ordNoArr, ","), enum.CentralKitchenForSchoolUserWithDayStateForCancel, enum.CentralKitchenForSchoolUserWithDayStateForCanceling, sDate.Format("2006-01-02"), eDate.Format("2006-01-02"), strings.Join(mealKindListArr, ",")) + nativeResults, err := db.QueryNativeString(db.Db, nativeSql) + var nativeResultsMap = map[string]map[int]int64{} + for _, v := range nativeResults { + if nativeResultsMap[v["ord_no"]] == nil { + nativeResultsMap[v["ord_no"]] = make(map[int]int64) + } + nativeResultsMap[v["ord_no"]][utils.StrToInt(v["kind"])] = utils.StrToInt64(v["total"]) + } + var list = map[string]map[string]int64{} centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} centralKitchenForSchoolUserWithDayDb.Set(0) @@ -1975,59 +1995,20 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD if list[v.Enterprise.Name] == nil { list[v.Enterprise.Name] = map[string]int64{} } - count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo( - v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, - enum.CentralKitchenForSchoolUserWithDayStateForCancel, enum.CentralKitchenForSchoolUserWithDayStateForCanceling, - req.StartDate, req.EndDate, []int{v.CentralKitchenForSchoolPackageOrdForReserve.Kind}) - if err2 != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return + var count int64 + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { + count = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForBreakfast] + list[v.Enterprise.Name][enum.CentralKitchenForSchoolUserWithDayKind(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast).String()] += nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForBreakfast] } - - for _, value := range req.MealKindList { - if value == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { - count1, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNoAndKind(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, req.StartDate, - req.EndDate, enum.CentralKitchenForSchoolUserWithDayKindForBreakfast, - enum.CentralKitchenForSchoolUserWithDayStateForCancel, - enum.CentralKitchenForSchoolUserWithDayStateForCanceling, - ) - if err2 != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - list[v.Enterprise.Name][enum.CentralKitchenForSchoolUserWithDayKind(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast).String()] += count1 - } - if value == enum.CentralKitchenForSchoolUserWithDayKindForLunch { - count2, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNoAndKind(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, req.StartDate, req.EndDate, - enum.CentralKitchenForSchoolUserWithDayKindForLunch, - enum.CentralKitchenForSchoolUserWithDayStateForCancel, - enum.CentralKitchenForSchoolUserWithDayStateForCanceling, - ) - if err2 != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - list[v.Enterprise.Name][enum.CentralKitchenForSchoolUserWithDayKind(enum.CentralKitchenForSchoolUserWithDayKindForLunch).String()] += count2 - } - if value == enum.CentralKitchenForSchoolUserWithDayKindForDinner { - count3, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNoAndKind(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, req.StartDate, req.EndDate, - enum.CentralKitchenForSchoolUserWithDayKindForDinner, - enum.CentralKitchenForSchoolUserWithDayStateForCancel, - enum.CentralKitchenForSchoolUserWithDayStateForCanceling, - ) - if err2 != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - list[v.Enterprise.Name][enum.CentralKitchenForSchoolUserWithDayKind(enum.CentralKitchenForSchoolUserWithDayKindForDinner).String()] += count3 - } + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { + count = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForLunch] + list[v.Enterprise.Name][enum.CentralKitchenForSchoolUserWithDayKind(enum.CentralKitchenForSchoolUserWithDayKindForLunch).String()] += nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForLunch] + } + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { + count = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForDinner] + list[v.Enterprise.Name][enum.CentralKitchenForSchoolUserWithDayKind(enum.CentralKitchenForSchoolUserWithDayKindForDinner).String()] += nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForDinner] } list[v.Enterprise.Name]["count"] += count - time.Sleep(20 * time.Millisecond) // 20毫秒 } titleList = []string{startDate.Format("2006-01-02") + "~~" + endDate.Format("2006-01-02") + " 预定数量统计表"}