|
|
@@ -377,6 +377,104 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta |
|
|
|
data[vv.Enterprise.Name][shopName]["合计"]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount) |
|
|
|
} |
|
|
|
|
|
|
|
xlsx.SetSheetRow("", "A1", &titleList) |
|
|
|
sheetIndex := 2 //第一个表是模板表 |
|
|
|
for k, v := range data { |
|
|
|
if k == "" { |
|
|
|
k = "未知" |
|
|
|
} |
|
|
|
xlsx.NewSheet(k) //1、新建表格 |
|
|
|
xlsx.CopySheet(1, sheetIndex) |
|
|
|
j := 4 //表头前三行被占用了,只能从第四行开始 |
|
|
|
for kk, vv := range v { |
|
|
|
if kk == "" { |
|
|
|
kk = k |
|
|
|
} |
|
|
|
xlsx.SetSheetRow(k, "A"+strconv.Itoa(j), &[]interface{}{kk, |
|
|
|
vv["早餐"]["num"], vv["早餐"]["amount"], |
|
|
|
vv["午餐"]["num"], vv["午餐"]["amount"], |
|
|
|
vv["晚餐"]["num"], vv["晚餐"]["amount"], |
|
|
|
vv["夜宵"]["num"], vv["夜宵"]["amount"], |
|
|
|
vv["合计"]["num"], vv["合计"]["amount"], |
|
|
|
}) |
|
|
|
j++ |
|
|
|
} |
|
|
|
sheetIndex++ |
|
|
|
} |
|
|
|
xlsx.DeleteSheet("template") //删除模板表 |
|
|
|
//将文件保存至服务器 |
|
|
|
xlsx.SaveAs("./static" + downloadPath) |
|
|
|
break |
|
|
|
case 3: |
|
|
|
//就餐数据统计表 |
|
|
|
xlsx, _ := excelize.OpenFile("./static/template/自营学校(就餐数据统计表).xlsx") |
|
|
|
fileName = "就餐数据统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" |
|
|
|
downloadPath = "/export/self_support_for_school/" + fileName |
|
|
|
|
|
|
|
//查询出所有的设备 |
|
|
|
//var deviceList []*model.Device |
|
|
|
//err := db.Db.Where("enterprise_id != 0").Find(&deviceList) |
|
|
|
//if err != nil { |
|
|
|
// logx.Error(err) |
|
|
|
// println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>1111Error:::", err.Error()) |
|
|
|
// return |
|
|
|
//} |
|
|
|
//var deviceListMapping = map[string]model.Device{} |
|
|
|
//for _, v := range deviceList { |
|
|
|
// deviceListMapping[v.DeviceSn] = *v |
|
|
|
//} |
|
|
|
|
|
|
|
var m []*db.SelfSupportForSchoolOrdWithUserIdentity |
|
|
|
sess := db.Db.Desc("self_support_for_school_ord.id") |
|
|
|
if req.EnterpriseId != 0 { |
|
|
|
sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId) |
|
|
|
} |
|
|
|
if req.StartDate != "" { |
|
|
|
sess.And("self_support_for_school_ord.face_time >= ?", req.StartDate) |
|
|
|
} |
|
|
|
if req.EndDate != "" { |
|
|
|
sess.And("self_support_for_school_ord.face_time <= ?", req.EndDate) |
|
|
|
} |
|
|
|
if req.EnterPriseKind != 0 { |
|
|
|
sess.And("enterprise.kind = ?", req.EnterPriseKind) |
|
|
|
} |
|
|
|
_, err := sess. |
|
|
|
Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id"). |
|
|
|
Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). |
|
|
|
Join("LEFT", "user", "user.id = user_identity.uid"). |
|
|
|
Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). |
|
|
|
Join("LEFT", "class", "class_with_user.class_id = class.id"). |
|
|
|
Join("LEFT", "grade", "class.grade_id = grade.id"). |
|
|
|
FindAndCount(&m) |
|
|
|
if err != nil { |
|
|
|
logx.Error(err) |
|
|
|
println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>Error:::", err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//整合数据 |
|
|
|
var data = map[string]map[string]map[string]map[string]float64{} |
|
|
|
shopName := req.StartDate + "~" + req.EndDate |
|
|
|
for _, vv := range m { |
|
|
|
if data[vv.Enterprise.Name] == nil { |
|
|
|
data[vv.Enterprise.Name] = make(map[string]map[string]map[string]float64) |
|
|
|
} |
|
|
|
if data[vv.Enterprise.Name][shopName] == nil { |
|
|
|
data[vv.Enterprise.Name][shopName] = make(map[string]map[string]float64) |
|
|
|
} |
|
|
|
mealZh := JudgeSelfSupportForMealTime(vv.SelfSupportForSchoolOrd.FaceTime) |
|
|
|
if data[vv.Enterprise.Name][shopName][mealZh] == nil { |
|
|
|
data[vv.Enterprise.Name][shopName][mealZh] = make(map[string]float64) |
|
|
|
} |
|
|
|
if data[vv.Enterprise.Name][shopName]["合计"] == nil { |
|
|
|
data[vv.Enterprise.Name][shopName]["合计"] = make(map[string]float64) |
|
|
|
} |
|
|
|
data[vv.Enterprise.Name][shopName][mealZh]["num"]++ |
|
|
|
data[vv.Enterprise.Name][shopName][mealZh]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount) |
|
|
|
data[vv.Enterprise.Name][shopName]["合计"]["num"]++ |
|
|
|
data[vv.Enterprise.Name][shopName]["合计"]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount) |
|
|
|
} |
|
|
|
|
|
|
|
xlsx.SetSheetRow("", "A1", &titleList) |
|
|
|
sheetIndex := 2 //第一个表是模板表 |
|
|
|
for k, v := range data { |
|
|
|