Browse Source

update

tmp
DengBiao 9 months ago
parent
commit
ed8686df25
1 changed files with 31 additions and 50 deletions
  1. +31
    -50
      app/admin/svc/svc_data_statisstics.go

+ 31
- 50
app/admin/svc/svc_data_statisstics.go View File

@@ -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("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>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("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>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("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>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("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>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") + " 预定数量统计表"}


Loading…
Cancel
Save