diff --git a/app/admin/svc/svc_data_statisstics.go b/app/admin/svc/svc_data_statisstics.go index 081bc58..2357fb9 100644 --- a/app/admin/svc/svc_data_statisstics.go +++ b/app/admin/svc/svc_data_statisstics.go @@ -877,40 +877,61 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD startDate, _ := time.ParseInLocation("2006-01-02 15:04:05", req.StartDate, time.Local) endDate, _ := time.ParseInLocation("2006-01-02 15:04:05", req.EndDate, time.Local) - for k2, v2 := range v1 { - if k2 == "" { - //若年级为空,则为教师餐 - continue - } - - for k3, v3 := range v2 { - xlsx.NewSheet(k3) - titleList = []string{startDate.Format("2006-01-02") + "~~" + endDate.Format("2006-01-02") + " [" + k1 + ", " + k3 + "] 班级明细"} - xlsx.SetSheetRow(k3, "A1", &titleList) - titleList = []string{"姓名", "早餐", "午餐", "晚餐"} - xlsx.SetSheetRow(k3, "A2", &titleList) - xlsx.MergeCell(k3, "A1", "D1") //合并单元格 - style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - panic(err) + //查询当前学校下的班级升序 + tmpEnterpriseDb := db.EnterpriseDb{} + tmpEnterpriseDb.Set() + tmpEnterprise, err11 := tmpEnterpriseDb.GetEnterpriseByName(k1) + if err11 != nil { + logx.Error(err11) + println("<<<>>>>Error:::", err11.Error()) + panic(err11) + } + tmpClassDb := db.ClassDb{} + tmpClassDb.Set(0) + classList, err := tmpClassDb.FindClassAscByEnterprise(tmpEnterprise.Id) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + panic(err) + } + for _, class := range *classList { + for k2, v2 := range v1 { + if k2 == "" { + //若年级为空,则为教师餐 + continue } - xlsx.SetCellStyle(k3, "A1", "D1", style) - xlsx.SetColWidth(k3, "A", "D", 20) - - var sumBreakfast, sumLunch, sumDinner = int64(0), int64(0), int64(0) - j := 3 //表头前两行用了,只能从第三行开始 - for k4, v4 := range v3 { + for k3, v3 := range v2 { + if class.Name != k3 { + continue + } + xlsx.NewSheet(k3) + titleList = []string{startDate.Format("2006-01-02") + "~~" + endDate.Format("2006-01-02") + " [" + k1 + ", " + k3 + "] 班级明细"} + xlsx.SetSheetRow(k3, "A1", &titleList) + titleList = []string{"姓名", "早餐", "午餐", "晚餐"} + xlsx.SetSheetRow(k3, "A2", &titleList) + xlsx.MergeCell(k3, "A1", "D1") //合并单元格 + style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + panic(err) + } + xlsx.SetCellStyle(k3, "A1", "D1", style) + xlsx.SetColWidth(k3, "A", "D", 20) + + var sumBreakfast, sumLunch, sumDinner = int64(0), int64(0), int64(0) + j := 3 //表头前两行用了,只能从第三行开始 + for k4, v4 := range v3 { + xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{ + k4, v4["breakfast"], v4["lunch"], v4["dinner"]}) + sumBreakfast += v4["breakfast"] + sumLunch += v4["lunch"] + sumDinner += v4["dinner"] + j++ + } xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{ - k4, v4["breakfast"], v4["lunch"], v4["dinner"]}) - sumBreakfast += v4["breakfast"] - sumLunch += v4["lunch"] - sumDinner += v4["dinner"] - j++ + "合计", sumBreakfast, sumLunch, sumDinner}) } - xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{ - "合计", sumBreakfast, sumLunch, sumDinner}) } } diff --git a/app/db/db_class.go b/app/db/db_class.go index 2562024..3472afe 100644 --- a/app/db/db_class.go +++ b/app/db/db_class.go @@ -39,6 +39,14 @@ func (classDb *ClassDb) FindClassByEnterprise(enterpriseId interface{}) (*[]mode return &m, nil } +func (classDb *ClassDb) FindClassAscByEnterprise(enterpriseId interface{}) (*[]model.Class, error) { + var m []model.Class + if err := classDb.Db.Asc("id").Where("enterprise_id =?", enterpriseId).Find(&m); err != nil { + return nil, logx.Error(err) + } + return &m, nil +} + func (classDb *ClassDb) ClassDeleteBySession(id interface{}) (int64, error) { if reflect.TypeOf(id).Kind() == reflect.Slice { return classDb.Db.In("id", id).Delete(model.Class{})