浏览代码

update

add_mode
DengBiao 1年前
父节点
当前提交
8c0602ec81
共有 4 个文件被更改,包括 124 次插入113 次删除
  1. +2
    -6
      app/admin/hdl/hdl_data_statistics.go
  2. +122
    -107
      app/admin/svc/svc_data_statisstics.go
  3. 二进制
     
  4. 二进制
     

+ 2
- 6
app/admin/hdl/hdl_data_statistics.go 查看文件

@@ -251,17 +251,13 @@ func SelfSupportForSchoolDataStatisticsList(c *gin.Context) {
"total": total,
"kind": []map[string]interface{}{
{
"name": "学生列表",
"name": "教师消费统计表",
"value": 1,
},
{
"name": "老师列表",
"name": "商家分餐数据统计表",
"value": 2,
},
{
"name": "消费明细表",
"value": 3,
},
},
}, nil)
return


+ 122
- 107
app/admin/svc/svc_data_statisstics.go 查看文件

@@ -221,110 +221,102 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta
var titleList []string
var fileName, downloadPath string
var now = time.Now()
xlsx := excelize.NewFile()
xlsx.SetSheetRow("Sheet1", "A1", &titleList)
switch req.Kind {
case 1:
//学生列表
fileName = "学生列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
//教师消费统计表
xlsx, _ := excelize.OpenFile("./static/upload/自营学校(教师消费统计表).xlsx")
fileName = "教师消费统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
downloadPath = "/export/self_support_for_school/" + fileName

//查找订单数据
sess := db.Db.Desc("user_identity.id")
sess.And("user_identity.identity =?", enum.UserIdentityForSelfSupportForStudent)
//查数据
var m []*db.SelfSupportForSchoolOrdWithUserIdentity
sess := db.Db.Desc("self_support_for_school_ord.id")
if req.EnterpriseId != 0 {
sess.And("user_identity.enterprise_id =?", req.EnterpriseId)
sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId)
}
if req.StartDate != "" {
sess.And("user_identity.create_at >= ?", req.StartDate)
sess.And("self_support_for_school_ord.face_time >= ?", req.StartDate)
}
if req.EndDate != "" {
sess.And("user_identity.create_at <= ?", req.EndDate)
sess.And("self_support_for_school_ord.face_time <= ?", req.EndDate)
}
var m []*db.UserIdentityWithUser
sess.And("user_identity.identity = ?", enum.UserIdentityForSelfSupportForTeacher) //只查询老师
_, err := sess.
Join("LEFT", "user", "user_identity.uid = user.id").
Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
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").
Join("LEFT", "self_support_for_user_face_info", "user_identity.id = self_support_for_user_face_info.user_identity_id").
FindAndCount(&m)
if err != nil {
logx.Error(err)
println("<<<<SelfSupportForSchoolDataStatisticsExport1>>>>>Error:::", err.Error())
println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>Error:::", err.Error())
return
}
titleList = []string{"单位名称", "姓名", "身份证号", "家长电话", "采脸方式", "支付状态", "刷脸状态", "年级", "班级", "注册时间"}
xlsx.SetSheetRow("Sheet1", "A1", &titleList)
j := 2 //表头被第一行用了,只能从第二行开始
for _, v := range m {
var kind string //采集人脸方式(1:个采 2:集采)
switch v.SelfSupportForUserFaceInfo.CollectFaceType {
case 1:
kind = "个采"
break
case 2:
kind = "集采"
break

//整合数据
var data map[string]map[string]map[string]map[string]float64
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][vv.UserIdentity.Name] == nil {
data[vv.Enterprise.Name][vv.UserIdentity.Name] = make(map[string]map[string]float64)
}
mealZh := JudgeSelfSupportForMealTime(vv.SelfSupportForSchoolOrd.FaceTime)
if data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh] == nil {
data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh] = make(map[string]float64)
}
data[vv.Enterprise.Name][vv.UserIdentity.Name]["编号"] = map[string]float64{
"id": float64(vv.UserIdentity.Id),
}
data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh]["num"]++
data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount)
data[vv.Enterprise.Name][vv.UserIdentity.Name]["合计"]["num"]++
data[vv.Enterprise.Name][vv.UserIdentity.Name]["合计"]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount)
}

xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Enterprise.Name, v.UserIdentity.Name, v.UserIdentity.IdNo, v.User.Phone, kind,
v.SelfSupportForUserFaceInfo.SchoolFacePaymentStatus, v.SelfSupportForUserFaceInfo.SchoolFacePassStatus, v.Grade.Name, v.Class.Name, v.UserIdentity.CreateAt})
j++
xlsx.SetSheetRow("", "A1", &titleList)
sheetIndex := 2 //第一个表是模板表
j := 3 //表头前两行被占用了,只能从第三行开始
for k, v := range data {
xlsx.NewSheet(k) //1、新建表格
xlsx.CopySheet(1, sheetIndex)
for kk, vv := range v {
xlsx.SetSheetRow(k, "A"+strconv.Itoa(j), &[]interface{}{utils.Float64ToStr(vv["编号"]["id"]), 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 2:
//教师列表
fileName = "教师列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
//商家分餐数据统计表
xlsx, _ := excelize.OpenFile("./static/upload/自营学校(商家分餐数据统计表).xlsx")
fileName = "商家分餐数据统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
downloadPath = "/export/self_support_for_school/" + fileName

//查找订单数据
sess := db.Db.Desc("user_identity.id")
sess.And("user_identity.identity =?", enum.UserIdentityForSelfSupportForTeacher)
if req.EnterpriseId != 0 {
sess.And("user_identity.enterprise_id =?", req.EnterpriseId)
}
if req.StartDate != "" {
sess.And("user_identity.create_at >= ?", req.StartDate)
}
if req.EndDate != "" {
sess.And("user_identity.create_at <= ?", req.EndDate)
}
var m []*db.UserIdentityWithUser
_, err := sess.
Join("LEFT", "user", "user_identity.uid = user.id").
Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
Join("LEFT", "self_support_for_user_face_info", "user_identity.id = self_support_for_user_face_info.user_identity_id").
FindAndCount(&m)
//查询出所有的设备
var deviceList []*db.Device
err := db.Db.Find(&deviceList)
if err != nil {
logx.Error(err)
println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>Error:::", err.Error())
return
}
titleList = []string{"单位名称", "姓名", "身份证号", "电话", "采脸方式", "支付状态", "刷脸状态", "注册时间"}
xlsx.SetSheetRow("Sheet1", "A1", &titleList)
j := 2 //表头被第一行用了,只能从第二行开始
for _, v := range m {
var kind string //采集人脸方式(1:个采 2:集采)
switch v.SelfSupportForUserFaceInfo.CollectFaceType {
case 1:
kind = "个采"
break
case 2:
kind = "集采"
break
}

xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Enterprise.Name, v.UserIdentity.Name, v.UserIdentity.IdNo, v.User.Phone, kind,
v.SelfSupportForUserFaceInfo.SchoolFacePaymentStatus, v.SelfSupportForUserFaceInfo.SchoolFacePassStatus, v.UserIdentity.CreateAt})
j++
var deviceListMapping map[string]model.Device
for _, v := range deviceListMapping {
deviceListMapping[v.DeviceSn] = v
}
break
case 3:
//消费明细表
fileName = "消费明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
downloadPath = "/export/self_support_for_school/" + fileName

var m []*db.SelfSupportForSchoolOrdWithUserIdentity
sess := db.Db.Desc("self_support_for_school_ord.id")
@@ -337,7 +329,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta
if req.EndDate != "" {
sess.And("self_support_for_school_ord.face_time <= ?", req.EndDate)
}
_, err := sess.
_, 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").
@@ -347,46 +339,54 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta
FindAndCount(&m)
if err != nil {
logx.Error(err)
println("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>Error:::", err.Error())
return
}

titleList = []string{"订单编号", "支付交易号", "用户手机号", "就餐人姓名", "学校名称", "年级", "班级", "金额", "支付状态", "就餐时间", "设备编号", "身份"}
xlsx.SetSheetRow("Sheet1", "A1", &titleList)
j := 2 //表头被第一行用了,只能从第二行开始
for _, v := range m {
var state string //支付状态(0:待支付 1:支付成功)
switch v.SelfSupportForSchoolOrd.OrderStatus {
case 1:
state = "待支付"
break
case 2:
state = "支付成功"
break
}

var identity string
switch v.UserIdentity.Identity {
case enum.UserIdentityForSelfSupportForTeacher:
identity = enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher)
break
case enum.UserIdentityForSelfSupportForStudent:
identity = enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent)
break
default:
identity = "未知"
}

xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.SelfSupportForSchoolOrd.OutOrderNo, v.SelfSupportForSchoolOrd.TradeNo, v.User.Phone, v.UserIdentity.Name, v.Enterprise.Name,
v.Grade.Name, v.Class.Name, v.SelfSupportForSchoolOrd.TradeAmount, state, v.SelfSupportForSchoolOrd.FaceTime, v.SelfSupportForSchoolOrd.DeviceSn, identity})
j++
}
//整合数据
var data map[string]map[string]map[string]map[string]float64
for _, vv := range m {
shopName := deviceListMapping[vv.SelfSupportForSchoolOrd.DeviceSn].Name
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)
}
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 //第一个表是模板表
j := 4 //表头前三行被占用了,只能从第四行开始
for k, v := range data {
xlsx.NewSheet(k) //1、新建表格
xlsx.CopySheet(1, sheetIndex)
for kk, vv := range v {
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
}

//将文件保存至服务器
xlsx.SaveAs("./static" + downloadPath)

//新增数据
selfSupportForSchoolExportRecordsDb := db.SelfSupportForSchoolExportRecordsDb{}
selfSupportForSchoolExportRecordsDb.Set()
@@ -1313,3 +1313,18 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
}

func JudgeSelfSupportForMealTime(mealDate string) (mealZh string) {
now := time.Now()
mealZh = "未知"
mealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", mealDate, time.Local)
for _, v := range md.SelfSupportForMealTimeMapping {
//判断时间大小
tmpFromTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+v["from"], time.Local)
tmpToTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+v["from"], time.Local)
if mealTime.After(tmpFromTime) && mealTime.Before(tmpToTime) {
mealZh = v["name"]
}
}
return
}

二进制
查看文件


二进制
查看文件


正在加载...
取消
保存