Browse Source

update

add_mode
DengBiao 1 year ago
parent
commit
55bf74c11e
4 changed files with 107 additions and 0 deletions
  1. +4
    -0
      app/admin/hdl/hdl_data_statistics.go
  2. +71
    -0
      app/admin/svc/svc_data_statisstics.go
  3. +32
    -0
      app/db/db_central_kitchen_for_school_user_with_day.go
  4. BIN
     

+ 4
- 0
app/admin/hdl/hdl_data_statistics.go View File

@@ -75,6 +75,10 @@ func CentralKitchenForSchoolDataStatisticsList(c *gin.Context) {
"name": "数据对比",
"value": 9,
},
{
"name": "就餐数据统计表",
"value": 10,
},
},
}, nil)
return


+ 71
- 0
app/admin/svc/svc_data_statisstics.go View File

@@ -1778,6 +1778,77 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD
//将文件保存至服务器
xlsx.SaveAs("./static" + downloadPath)
break
case 10:
//就餐数据统计表
xlsx, _ := excelize.OpenFile("./static/template/央厨学校(就餐数据统计表).xlsx")
fileName = "就餐数据统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
downloadPath = "/export/central_kitchen_for_school/" + fileName

var list = map[string]map[string]map[string]float64{}
var dates []string

if req.StartDate != "" {
centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
centralKitchenForSchoolUserWithDayDb.Set(0)
sTime, _ := time.ParseInLocation("2006-01-02 15:04:05", req.StartDate, time.Local)
eTime, _ := time.ParseInLocation("2006-01-02 15:04:05", req.EndDate, time.Local)
diffDays := int(eTime.Sub(sTime).Hours() / 24)
for i := 0; i <= diffDays; i++ {
date := sTime.AddDate(0, 0, i)
dateName := date.Format("2006-01-02")
dates = append(dates, dateName)
for _, vv := range req.MealKindList {
tmpSum, err := centralKitchenForSchoolUserWithDayDb.SumCentralKitchenForSchoolUserWithDayByKind(req.EnterpriseId, dateName, dateName, vv, enum.CentralKitchenForSchoolUserWithDayStateForCancel)
if err != nil {
logx.Error(err)
println("<<<<CentralKitchenForSchoolDataStatisticsExport9>>>>>Error:::", err.Error())
panic(err)
}
tmpCount, err := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByKind(req.EnterpriseId, dateName, dateName, vv, enum.CentralKitchenForSchoolUserWithDayStateForCancel)
if err != nil {
logx.Error(err)
println("<<<<CentralKitchenForSchoolDataStatisticsExport9>>>>>Error:::", err.Error())
panic(err)
}
if list[dateName] == nil {
list[dateName] = map[string]map[string]float64{}
}
if list[dateName][enum.CentralKitchenForSchoolUserWithDayKind(vv).String()] == nil {
list[dateName][enum.CentralKitchenForSchoolUserWithDayKind(vv).String()] = map[string]float64{}
}

list[dateName][enum.CentralKitchenForSchoolUserWithDayKind(vv).String()]["sum"] = tmpSum
list[dateName][enum.CentralKitchenForSchoolUserWithDayKind(vv).String()]["count"] = float64(tmpCount)
list[dateName]["合计"]["sum"] += tmpSum
list[dateName]["合计"]["count"] += float64(tmpCount)
}
}
}

xlsx.SetSheetRow("", "A1", &titleList)
sheetIndex := 2 //第一个表是模板表
xlsx.NewSheet("sheet1") //1、新建表格
xlsx.CopySheet(1, sheetIndex)
j := 4 //表头前三行被占用了,只能从第四行开始

for _, date := range dates {
for kk, v := range list {
if date == kk {
xlsx.SetSheetRow("sheet1", "A"+strconv.Itoa(j), &[]interface{}{kk,
v["早餐"]["count"], v["早餐"]["sum"],
v["午餐"]["count"], v["午餐"]["sum"],
v["晚餐"]["count"], v["晚餐"]["sum"],
v["合计"]["count"], v["合计"]["sum"],
})
j++
}
sheetIndex++
}
}
xlsx.DeleteSheet("template") //删除模板表
//将文件保存至服务器
xlsx.SaveAs("./static" + downloadPath)
break
}

//新增数据


+ 32
- 0
app/db/db_central_kitchen_for_school_user_with_day.go View File

@@ -103,6 +103,38 @@ func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb
return count, nil
}

func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) SumCentralKitchenForSchoolUserWithDayByKind(enterpriseId int, startDate, endDate string, kind, state int) (sum float64, err error) {
var m model.CentralKitchenForSchoolUserWithDay
if enterpriseId != 0 {
sum, err = centralKitchenForSchoolUserWithDayDb.Db.Where("kind =?", kind).
And("date >= ?", startDate).And("date <= ?", endDate).And("enterprise_id =?", enterpriseId).
And("state !=?", state).
Sum(&m, "amount")
} else {
sum, err = centralKitchenForSchoolUserWithDayDb.Db.Where("kind =?", kind).
And("date >= ?", startDate).And("date <= ?", endDate).
And("state !=?", state).
Sum(&m, "amount")
}
return sum, nil
}

func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) CountCentralKitchenForSchoolUserWithDayByKind(enterpriseId int, startDate, endDate string, kind, state int) (sum int64, err error) {
var m model.CentralKitchenForSchoolUserWithDay
if enterpriseId != 0 {
sum, err = centralKitchenForSchoolUserWithDayDb.Db.Where("kind =?", kind).
And("date >= ?", startDate).And("date <= ?", endDate).And("enterprise_id =?", enterpriseId).
And("state !=?", state).
Count(&m)
} else {
sum, err = centralKitchenForSchoolUserWithDayDb.Db.Where("kind =?", kind).
And("date >= ?", startDate).And("date <= ?", endDate).
And("state !=?", state).
Count(&m)
}
return sum, nil
}

func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) CountCentralKitchenForSchoolUserWithDay(ordNo, startDate, endDate string, kind int) (count int64, err error) {
var m model.CentralKitchenForSchoolUserWithDay
count, err = centralKitchenForSchoolUserWithDayDb.Db.Where("ord_no =?", ordNo).


BIN
View File


Loading…
Cancel
Save