Ver código fonte

update

add_mode
DengBiao 1 ano atrás
pai
commit
4cf5cb1fa2
2 arquivos alterados com 60 adições e 31 exclusões
  1. +52
    -31
      app/admin/svc/svc_data_statisstics.go
  2. +8
    -0
      app/db/db_class.go

+ 52
- 31
app/admin/svc/svc_data_statisstics.go Ver arquivo

@@ -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("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
panic(err)
//查询当前学校下的班级升序
tmpEnterpriseDb := db.EnterpriseDb{}
tmpEnterpriseDb.Set()
tmpEnterprise, err11 := tmpEnterpriseDb.GetEnterpriseByName(k1)
if err11 != nil {
logx.Error(err11)
println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err11.Error())
panic(err11)
}
tmpClassDb := db.ClassDb{}
tmpClassDb.Set(0)
classList, err := tmpClassDb.FindClassAscByEnterprise(tmpEnterprise.Id)
if err != nil {
logx.Error(err)
println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>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("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>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})
}
}



+ 8
- 0
app/db/db_class.go Ver arquivo

@@ -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{})


Carregando…
Cancelar
Salvar