From fe716c7e3abbc8e4659edb8447edf09a7e82d297 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Thu, 7 Sep 2023 15:32:26 +0800 Subject: [PATCH] up[date --- app/admin/hdl/hdl_home_page.go | 66 ++++++++++++------- app/admin/md/md_app_redis_key.go | 2 + app/admin/md/md_enterprise_manage.go | 13 ++-- .../svc_enterprise_manage.go | 11 +--- .../svc/enterprise_manage/svc_nursing_home.go | 6 +- 5 files changed, 57 insertions(+), 41 deletions(-) diff --git a/app/admin/hdl/hdl_home_page.go b/app/admin/hdl/hdl_home_page.go index 6609a03..33773f3 100644 --- a/app/admin/hdl/hdl_home_page.go +++ b/app/admin/hdl/hdl_home_page.go @@ -1,10 +1,14 @@ package hdl import ( + "applet/app/admin/md" + "applet/app/admin/svc" "applet/app/db" "applet/app/e" "applet/app/enum" "applet/app/utils" + "applet/app/utils/cache" + "encoding/json" "fmt" "github.com/gin-gonic/gin" "time" @@ -137,36 +141,54 @@ func ThisWeekData(c *gin.Context) { } func ThisMonthData(c *gin.Context) { - now := time.Now() var list []map[string]interface{} - for i := -29; i <= 0; i++ { - day := now.AddDate(0, 0, i).Format("2006-01-02") //7日前 - dayStart := now.AddDate(0, 0, i).Format("2006-01-02 15:04:05") - dayEnd := now.AddDate(0, 0, i+1).Format("2006-01-02 15:04:05") - sql1 := fmt.Sprintf("SELECT count(*) as total FROM self_support_for_school_ord where order_status = 2 and face_time >= '%s' and face_time < '%s'", dayStart, dayEnd) //统计今日"自营-学校"收益 - sql2 := fmt.Sprintf("SELECT count(*) as total FROM central_kitchen_for_school_package_ord where state = 1 and create_at >= '%s' and create_at < '%s'", dayStart, dayEnd) //统计今日"央厨-学校"收益 - mapArr1, err := db.QueryNativeString(db.Db, sql1) - if err != nil { + admin := svc.GetUser(c) + cacheKey := fmt.Sprintf(md.AdminHomePageDataKey, utils.GetIP(c.Request), utils.AnyToString(admin.AdmId)) + var adminHomePageDataString string + adminHomePageDataString, _ = cache.GetString(cacheKey) + if adminHomePageDataString != "" { + if err := json.Unmarshal([]byte(adminHomePageDataString), &list); err != nil { e.OutErr(c, e.ERR, err.Error()) return } - mapArr2, err := db.QueryNativeString(db.Db, sql2) + } else { + now := time.Now() + for i := -29; i <= 0; i++ { + day := now.AddDate(0, 0, i).Format("2006-01-02") //7日前 + dayStart := now.AddDate(0, 0, i).Format("2006-01-02 15:04:05") + dayEnd := now.AddDate(0, 0, i+1).Format("2006-01-02 15:04:05") + sql1 := fmt.Sprintf("SELECT count(*) as total FROM self_support_for_school_ord where order_status = 2 and face_time >= '%s' and face_time < '%s'", dayStart, dayEnd) //统计今日"自营-学校"收益 + sql2 := fmt.Sprintf("SELECT count(*) as total FROM central_kitchen_for_school_package_ord where state = 1 and create_at >= '%s' and create_at < '%s'", dayStart, dayEnd) //统计今日"央厨-学校"收益 + mapArr1, err := db.QueryNativeString(db.Db, sql1) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + mapArr2, err := db.QueryNativeString(db.Db, sql2) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + var result1, result2 int + if mapArr1 != nil { + result1 = utils.StrToInt(mapArr1[0]["total"]) + } + if mapArr2 != nil { + result2 = utils.StrToInt(mapArr2[0]["total"]) + } + list = append(list, map[string]interface{}{ + "date": day, + "self_support_for_school": result1, + "central_kitchen_for_school": result2, + }) + } + marshal, err := json.Marshal(list) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } - var result1, result2 int - if mapArr1 != nil { - result1 = utils.StrToInt(mapArr1[0]["total"]) - } - if mapArr2 != nil { - result2 = utils.StrToInt(mapArr2[0]["total"]) - } - list = append(list, map[string]interface{}{ - "date": day, - "self_support_for_school": result1, - "central_kitchen_for_school": result2, - }) + adminHomePageDataString = string(marshal) + _, err = cache.SetEx(cacheKey, adminHomePageDataString, md.AdminHomePageDataCacheTime) } e.OutSuc(c, map[string]interface{}{ diff --git a/app/admin/md/md_app_redis_key.go b/app/admin/md/md_app_redis_key.go index c98286c..7bf0e27 100644 --- a/app/admin/md/md_app_redis_key.go +++ b/app/admin/md/md_app_redis_key.go @@ -6,6 +6,8 @@ const ( JwtTokenCacheTime = 3600 * 24 AdminRolePermissionKey = "%s:smart_canteen_admin_role_permission:%s" // 占位符:ip, admin:id AdminRolePermissionCacheTime = 3600 * 24 * 0.5 + AdminHomePageDataKey = "%s:smart_canteen_admin_home_data:%s" // 占位符:ip, admin:id + AdminHomePageDataCacheTime = 60 * 10 CfgCacheTime = 86400 AppCfgCacheKey = "smart_canteen:%s" // 占位符: key的第一个字母 WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 diff --git a/app/admin/md/md_enterprise_manage.go b/app/admin/md/md_enterprise_manage.go index a1915c7..d92e63e 100644 --- a/app/admin/md/md_enterprise_manage.go +++ b/app/admin/md/md_enterprise_manage.go @@ -1,12 +1,13 @@ package md type EnterpriseUserListReq struct { - EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` - Limit int `json:"limit" binding:"required"` - Page int `json:"page" binding:"required"` - Nickname string `json:"nickname" label:"支付宝昵称"` - Phone string `json:"phone" label:"手机号"` - IsTeacher int `json:"is_teacher" label:"是否教师"` + EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` + Limit int `json:"limit" binding:"required"` + Page int `json:"page" binding:"required"` + Nickname string `json:"nickname" label:"支付宝昵称"` + Phone string `json:"phone" label:"手机号"` + IsTeacher int `json:"is_teacher" label:"是否教师"` + EnterpriseName string `json:"enterprise_name" label:"校企名称"` } type EnterpriseUserListByCentralKitchenForSchoolStruct struct { diff --git a/app/admin/svc/enterprise_manage/svc_enterprise_manage.go b/app/admin/svc/enterprise_manage/svc_enterprise_manage.go index 0301e55..5512204 100644 --- a/app/admin/svc/enterprise_manage/svc_enterprise_manage.go +++ b/app/admin/svc/enterprise_manage/svc_enterprise_manage.go @@ -131,8 +131,6 @@ func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.Ente return } resp.Total = count - classWithUserDb := db.ClassWithUserDb{} - classWithUserDb.Set() for _, v := range m { temp := md.EnterpriseUserListByNursingHomeStruct{ Id: v.Id, @@ -143,19 +141,12 @@ func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.Ente } for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] { fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)]) - data, err2 := classWithUserDb.GetInfoByUserIdentityId(v1.Id) - if err2 != nil { - return resp, err2 - } - if data == nil { - continue - } temp.UserIdentities = append(temp.UserIdentities, struct { Id int `json:"id" label:"身份id"` IdNo string `json:"id_no" label:"身份证号"` EnterpriseName string `json:"enterprise_name" label:"单位名"` Name string `json:"name" label:"姓名"` - }{Id: v1.Id, IdNo: data.UserIdentity.IdNo, EnterpriseName: data.Enterprise.Name, Name: data.UserIdentity.Name}) + }{Id: v1.Id, IdNo: v1.IdNo, EnterpriseName: req.EnterpriseName, Name: v1.Name}) } resp.List = append(resp.List, temp) } diff --git a/app/admin/svc/enterprise_manage/svc_nursing_home.go b/app/admin/svc/enterprise_manage/svc_nursing_home.go index 6ece9be..4c8d431 100644 --- a/app/admin/svc/enterprise_manage/svc_nursing_home.go +++ b/app/admin/svc/enterprise_manage/svc_nursing_home.go @@ -149,8 +149,8 @@ func NursingHomeOrdList(req md.NursingHomeOrdListReq) (resp []md.NursingHomeOrdL var m []*db.NursingHomePackageOrdWithUserIdentity count, err = sess. Join("LEFT", "user_identity", "nursing_home_package_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", "enterprise", "enterprise.id = nursing_home_package_ord.enterprise_id"). + Join("LEFT", "user", "user.id = nursing_home_package_ord.uid"). Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) if err != nil { return nil, 0, err @@ -163,7 +163,7 @@ func NursingHomeOrdList(req md.NursingHomeOrdListReq) (resp []md.NursingHomeOrdL Uid: v.UserIdentity.Uid, UserIdentityId: v.UserIdentity.Id, UserIdentityKind: v.UserIdentity.Kind, - UserIdentityName: v.UserIdentity.Name, + UserIdentityName: v.NursingHomePackageOrd.UserIdentityName, TotalPrice: v.TotalPrice, Kind: v.NursingHomePackageOrd.Kind, OutTradeNo: v.NursingHomePackageOrd.OutTradeNo,