diff --git a/app/admin/svc/svc_data_statisstics.go b/app/admin/svc/svc_data_statisstics.go index ae5c5ba..e26d304 100644 --- a/app/admin/svc/svc_data_statisstics.go +++ b/app/admin/svc/svc_data_statisstics.go @@ -15,6 +15,7 @@ import ( "io" "os" "strconv" + "strings" "time" ) @@ -1039,6 +1040,27 @@ 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"]) + } + centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} centralKitchenForSchoolUserWithDayDb.Set(0) var list = map[string]map[string]map[string]map[string]int64{} @@ -1054,26 +1076,30 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(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 - } - time.Sleep(2 * time.Millisecond) // 2毫秒 + //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 + //} + //time.Sleep(2 * time.Millisecond) // 2毫秒 + //if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { + // list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["breakfast"] += count + //} + //if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { + // list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["lunch"] += count + //} + //if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { + // list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["dinner"] += count + //} + + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["breakfast"] = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForBreakfast] + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["lunch"] = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForLunch] + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["dinner"] = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForDinner] - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["breakfast"] += count - } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["lunch"] += count - } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["dinner"] += count - } } for k1, v1 := range list { @@ -1251,6 +1277,27 @@ 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]map[string]map[string]map[string]int64{} var xlsFileName, xlsDownloadPath []string centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} @@ -1269,29 +1316,33 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] = make(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(err2) - println("<<<>>>>Error:::", err2.Error()) - return - } - if count == 0 { - continue - } - time.Sleep(2 * time.Millisecond) // 2毫秒 - - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"] += count - } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"] += count - } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"] += count - } + //count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo( + // v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, + // enum.CentralKitchenForSchoolUserWithDayStateForCancel, enum.CentralKitchenForSchoolUserWithDayStateForCanceling, + // req.StartDate, req.EndDate, []int{v.CentralKitchenForSchoolPackageOrdForReserve.Kind}) + //if err2 != nil { + // logx.Error(err2) + // println("<<<>>>>Error:::", err2.Error()) + // return + //} + //if count == 0 { + // continue + //} + //time.Sleep(2 * time.Millisecond) // 2毫秒 + // + //if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { + // list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"] += count + //} + //if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { + // list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"] += count + //} + //if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { + // list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"] += count + //} + + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"] = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForBreakfast] + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"] = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForLunch] + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"] = nativeResultsMap[v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo][enum.CentralKitchenForSchoolUserWithDayKindForDinner] } for k1, v1 := range list {