|
|
@@ -353,22 +353,44 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta |
|
|
|
fileName = "商家分餐数据统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" |
|
|
|
downloadPath = "/export/self_support_for_school/" + fileName |
|
|
|
|
|
|
|
//查询出所有的商家 |
|
|
|
var merchantList []*model.Merchant |
|
|
|
err := db.Db.Where("enterprise_id != 0").OrderBy("CONVERT(name USING gbk) ASC").Find(&merchantList) |
|
|
|
if err != nil { |
|
|
|
logx.Error(err) |
|
|
|
println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>1111Error:::", err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//查询出所有的设备 |
|
|
|
var deviceList []*model.Device |
|
|
|
err := db.Db.Where("enterprise_id != 0").OrderBy("CONVERT(name USING gbk) ASC").Find(&deviceList) |
|
|
|
err = db.Db.Where("enterprise_id != 0").OrderBy("CONVERT(name USING gbk) ASC").Find(&deviceList) |
|
|
|
if err != nil { |
|
|
|
logx.Error(err) |
|
|
|
println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>1111Error:::", err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
var merchantListMapping = map[int]model.Merchant{} |
|
|
|
var merchantDeviceListMapping = map[int]map[string]model.Device{} |
|
|
|
var deviceListMapping = map[string]model.Device{} |
|
|
|
var deviceNameArr []string |
|
|
|
var isHasDeviceName = map[string]bool{} |
|
|
|
for _, v := range deviceList { |
|
|
|
if merchantDeviceListMapping[v.MerchantId] == nil { |
|
|
|
merchantDeviceListMapping[v.MerchantId] = map[string]model.Device{} |
|
|
|
} |
|
|
|
merchantDeviceListMapping[v.MerchantId][v.DeviceSn] = *v |
|
|
|
deviceListMapping[v.DeviceSn] = *v |
|
|
|
deviceNameArr = append(deviceNameArr, v.Name) |
|
|
|
if !isHasDeviceName[v.Name] { |
|
|
|
deviceNameArr = append(deviceNameArr, v.Name) |
|
|
|
isHasDeviceName[v.Name] = true |
|
|
|
} |
|
|
|
} |
|
|
|
for _, v := range merchantList { |
|
|
|
merchantListMapping[v.Id] = *v |
|
|
|
} |
|
|
|
|
|
|
|
var m []*db.SelfSupportForSchoolOrdWithUserIdentity |
|
|
|
var m []*db.SelfSupportForSchoolOrdWithUserIdentityV2 |
|
|
|
sess := db.Db.Desc("self_support_for_school_ord.id").Where("self_support_for_school_ord.order_status =?", enum.SelfSupportForSchoolOrdOrderStatusForSuccess) |
|
|
|
if req.EnterpriseId != 0 { |
|
|
|
sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId) |
|
|
@@ -383,7 +405,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta |
|
|
|
sess.And("enterprise.kind = ?", req.EnterPriseKind) |
|
|
|
} |
|
|
|
_, err = sess. |
|
|
|
Join("LEFT", "enterprise", "enterprise.id = self_support_for_school_ord.enterprise_id"). |
|
|
|
Join("LEFT", "enterprise", "self_support_for_school_ord.enterprise_id = enterprise.id"). |
|
|
|
FindAndCount(&m) |
|
|
|
if err != nil { |
|
|
|
logx.Error(err) |
|
|
@@ -392,26 +414,32 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta |
|
|
|
} |
|
|
|
|
|
|
|
//整合数据 |
|
|
|
var data = map[string]map[string]map[string]map[string]float64{} |
|
|
|
var data = map[string]map[string]map[string]map[string]map[string]float64{} |
|
|
|
for _, vv := range m { |
|
|
|
shopName := deviceListMapping[vv.SelfSupportForSchoolOrd.DeviceSn].Name |
|
|
|
device := deviceListMapping[vv.SelfSupportForSchoolOrd.DeviceSn] |
|
|
|
shopName := merchantListMapping[device.MerchantId].Name |
|
|
|
deviceName := device.Name |
|
|
|
if data[vv.Enterprise.Name] == nil { |
|
|
|
data[vv.Enterprise.Name] = make(map[string]map[string]map[string]float64) |
|
|
|
data[vv.Enterprise.Name] = make(map[string]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) |
|
|
|
data[vv.Enterprise.Name][shopName] = make(map[string]map[string]map[string]float64) |
|
|
|
} |
|
|
|
if data[vv.Enterprise.Name][shopName][deviceName] == nil { |
|
|
|
data[vv.Enterprise.Name][shopName][deviceName] = 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][deviceName][mealZh] == nil { |
|
|
|
data[vv.Enterprise.Name][shopName][deviceName][mealZh] = make(map[string]float64) |
|
|
|
} |
|
|
|
if data[vv.Enterprise.Name][shopName]["合计"] == nil { |
|
|
|
data[vv.Enterprise.Name][shopName]["合计"] = make(map[string]float64) |
|
|
|
if data[vv.Enterprise.Name][shopName][deviceName]["合计"] == nil { |
|
|
|
data[vv.Enterprise.Name][shopName][deviceName]["合计"] = 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) |
|
|
|
data[vv.Enterprise.Name][shopName][deviceName][mealZh]["num"]++ |
|
|
|
data[vv.Enterprise.Name][shopName][deviceName][mealZh]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount) |
|
|
|
data[vv.Enterprise.Name][shopName][deviceName]["合计"]["num"]++ |
|
|
|
data[vv.Enterprise.Name][shopName][deviceName]["合计"]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount) |
|
|
|
} |
|
|
|
|
|
|
|
xlsx.SetSheetRow("", "A1", &titleList) |
|
|
@@ -426,42 +454,64 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta |
|
|
|
j := 4 //表头前三行被占用了,只能从第四行开始 |
|
|
|
var breakFastTotal, lunchTotal, dinnerTotal, supperTotal, totalTotal float64 |
|
|
|
var breakFastAmountTotal, lunchAmountTotal, dinnerAmountTotal, supperAmountTotal, totalAmountTotal float64 |
|
|
|
for _, device := range deviceNameArr { |
|
|
|
for kk, vv := range v { |
|
|
|
if kk == "" { |
|
|
|
kk = k |
|
|
|
for kk, vv := range v { |
|
|
|
var startRow = 0 |
|
|
|
var endRow = 0 |
|
|
|
for _, device := range deviceNameArr { |
|
|
|
for kkk, vvv := range vv { |
|
|
|
if kkk == "" { |
|
|
|
kkk = k |
|
|
|
} |
|
|
|
if device == kkk { |
|
|
|
xlsx.SetSheetRow(k, "A"+strconv.Itoa(j), &[]interface{}{kk, kkk, |
|
|
|
vvv["早餐"]["num"], vvv["早餐"]["amount"], |
|
|
|
vvv["午餐"]["num"], vvv["午餐"]["amount"], |
|
|
|
vvv["晚餐"]["num"], vvv["晚餐"]["amount"], |
|
|
|
vvv["夜宵"]["num"], vvv["夜宵"]["amount"], |
|
|
|
vvv["合计"]["num"], vvv["合计"]["amount"], |
|
|
|
}) |
|
|
|
|
|
|
|
breakFastTotal += vvv["早餐"]["num"] |
|
|
|
lunchTotal += vvv["午餐"]["num"] |
|
|
|
dinnerTotal += vvv["晚餐"]["num"] |
|
|
|
supperTotal += vvv["夜宵"]["num"] |
|
|
|
totalTotal += vvv["合计"]["num"] |
|
|
|
breakFastAmountTotal += vvv["早餐"]["amount"] |
|
|
|
lunchAmountTotal += vvv["午餐"]["amount"] |
|
|
|
dinnerAmountTotal += vvv["晚餐"]["amount"] |
|
|
|
supperAmountTotal += vvv["夜宵"]["amount"] |
|
|
|
totalAmountTotal += vvv["合计"]["amount"] |
|
|
|
|
|
|
|
if startRow == 0 { |
|
|
|
startRow = j |
|
|
|
} |
|
|
|
endRow = j |
|
|
|
j++ |
|
|
|
} |
|
|
|
} |
|
|
|
if device == kk { |
|
|
|
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"], |
|
|
|
}) |
|
|
|
} |
|
|
|
xlsx.SetSheetRow(k, "A"+strconv.Itoa(j), &[]interface{}{"", "合计", |
|
|
|
breakFastTotal, breakFastAmountTotal, |
|
|
|
lunchTotal, lunchAmountTotal, |
|
|
|
dinnerTotal, dinnerAmountTotal, |
|
|
|
supperTotal, supperAmountTotal, |
|
|
|
totalTotal, totalAmountTotal, |
|
|
|
}) |
|
|
|
if startRow == 0 { |
|
|
|
startRow = j |
|
|
|
} |
|
|
|
endRow = j |
|
|
|
j++ |
|
|
|
|
|
|
|
breakFastTotal += vv["早餐"]["num"] |
|
|
|
lunchTotal += vv["午餐"]["num"] |
|
|
|
dinnerTotal += vv["晚餐"]["num"] |
|
|
|
supperTotal += vv["夜宵"]["num"] |
|
|
|
totalTotal += vv["合计"]["num"] |
|
|
|
breakFastAmountTotal += vv["早餐"]["amount"] |
|
|
|
lunchAmountTotal += vv["午餐"]["amount"] |
|
|
|
dinnerAmountTotal += vv["晚餐"]["amount"] |
|
|
|
supperAmountTotal += vv["夜宵"]["amount"] |
|
|
|
totalAmountTotal += vv["合计"]["amount"] |
|
|
|
j++ |
|
|
|
} |
|
|
|
style, err := xlsx.NewStyle(`{"alignment":{"horizontal":"center", "vertical": "center"}}`) |
|
|
|
if err != nil { |
|
|
|
logx.Error(err) |
|
|
|
println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>Error:::", err.Error()) |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
xlsx.MergeCell(k, "A"+utils.IntToStr(startRow), "A"+utils.IntToStr(endRow)) //合并单元格 |
|
|
|
xlsx.SetCellStyle(k, "A"+utils.IntToStr(startRow), "A"+utils.IntToStr(endRow), style) |
|
|
|
} |
|
|
|
|
|
|
|
xlsx.SetSheetRow(k, "A"+strconv.Itoa(j), &[]interface{}{"合计", |
|
|
|
breakFastTotal, breakFastAmountTotal, |
|
|
|
lunchTotal, lunchAmountTotal, |
|
|
|
dinnerTotal, dinnerAmountTotal, |
|
|
|
supperTotal, supperAmountTotal, |
|
|
|
totalTotal, totalAmountTotal, |
|
|
|
}) |
|
|
|
sheetIndex++ |
|
|
|
} |
|
|
|
xlsx.DeleteSheet("template") //删除模板表 |
|
|
|