diff --git a/app/admin/hdl/enterprise_manage/hdl_enterprise.go b/app/admin/hdl/enterprise_manage/hdl_enterprise.go index 9b8cd1a..ebc5e8c 100644 --- a/app/admin/hdl/enterprise_manage/hdl_enterprise.go +++ b/app/admin/hdl/enterprise_manage/hdl_enterprise.go @@ -37,6 +37,11 @@ func EnterpriseManageInfo(c *gin.Context) { case enum.EnterprisePvdByCentralKitchenForFactory: break case enum.EnterprisePvdBySelfSupportForSchool: + err, resp = svc.SelfSupportForSchoolInfo(utils.StrToInt(enterpriseId)) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } break case enum.EnterprisePvdBySelfSupportForFactory: break diff --git a/app/admin/hdl/hdl_enterprise.go b/app/admin/hdl/hdl_enterprise.go index 9a34651..302820a 100644 --- a/app/admin/hdl/hdl_enterprise.go +++ b/app/admin/hdl/hdl_enterprise.go @@ -98,16 +98,30 @@ func SchoolBelowGrade(c *gin.Context) { func SchoolGradeBelowClass(c *gin.Context) { gradeId := c.DefaultQuery("grade_id", "") + enterpriseId := c.DefaultQuery("enterprise_id", "") classDb := db.ClassDb{} - classDb.Set(utils.StrToInt(gradeId)) - classList, err := classDb.FindClass() - if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) - return + + if gradeId != "" { + classDb.Set(utils.StrToInt(gradeId)) + classList, err := classDb.FindClass() + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + e.OutSuc(c, map[string]interface{}{ + "list": classList, + }, nil) + } else { + classDb.Set(0) + classList, err := classDb.FindClassByEnterprise(enterpriseId) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + e.OutSuc(c, map[string]interface{}{ + "list": classList, + }, nil) } - e.OutSuc(c, map[string]interface{}{ - "list": classList, - }, nil) return } diff --git a/app/admin/md/md_app_redis_key.go b/app/admin/md/md_app_redis_key.go index 6f0865b..c98286c 100644 --- a/app/admin/md/md_app_redis_key.go +++ b/app/admin/md/md_app_redis_key.go @@ -7,6 +7,6 @@ const ( AdminRolePermissionKey = "%s:smart_canteen_admin_role_permission:%s" // 占位符:ip, admin:id AdminRolePermissionCacheTime = 3600 * 24 * 0.5 CfgCacheTime = 86400 - AppCfgCacheKey = "one_item_one_code:%s" // 占位符: key的第一个字母 - WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 + AppCfgCacheKey = "smart_canteen:%s" // 占位符: key的第一个字母 + WxOfficialAccountCacheKey = "wx_official_account" // 占位符: key的第一个字母 ) diff --git a/app/admin/md/md_self_support_for_school.go b/app/admin/md/md_self_support_for_school.go new file mode 100644 index 0000000..ba7cf3f --- /dev/null +++ b/app/admin/md/md_self_support_for_school.go @@ -0,0 +1,15 @@ +package md + +type SelfSupportForSchoolInfoResp struct { + Name string `json:"name" label:"名称"` + Memo string `json:"memo" label:"备注"` + Kind string `json:"kind" label:"种类(1:央厨-学校 2:央厨-工厂 3:自营-学校 4:自营-工厂)"` + State string `json:"state" label:"状态(1:正常 2:冻结)"` + TeacherNum int64 `json:"teacher_num" label:"教师数量"` + StudentNum int64 `json:"student_num" label:"学生数量"` + ClassNum int64 `json:"class_num" label:"班级数量"` + ConcentrateSchoolFacePassNum int64 `json:"concentrate_school_face_pass_num" label:"集采数量"` + SingleSchoolFacePassNum int64 `json:"single_school_face_pass_num" label:"个采数量"` + SchoolFacePassNum int64 `json:"school_face_pass_num" label:"校园一脸通行开通数量"` + SchoolFacePaymentNum int64 `json:"school_face_payment_num" label:"校园一脸通行刷脸支付开通数量"` +} diff --git a/app/admin/svc/enterprise_manage/svc_self_support_for_school.go b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go index a993aad..031c34a 100644 --- a/app/admin/svc/enterprise_manage/svc_self_support_for_school.go +++ b/app/admin/svc/enterprise_manage/svc_self_support_for_school.go @@ -122,6 +122,7 @@ func SelfSupportForSchoolUserUpdate(req md.SelfSupportForSchoolUserUpdateReq) (e selfSupportForUserFaceInfoDb.Set(insertId) _, err = selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(&model.SelfSupportForUserFaceInfo{ + EnterpriseId: req.EnterpriseId, UserIdentityId: insertId, CollectFaceType: 1, //默认个采 SchoolCode: selfSupportForSchoolInfo.SchoolCode, @@ -414,7 +415,7 @@ func SelfSupportForSchoolStudentDelete(req md.SelfSupportForSchoolStudentDeleteR } //3、删除 self_support_for_user_face_info - _, err = db.Db.In("user_identity_id =?", req.UserIdentityIds).Delete(model.SelfSupportForUserFaceInfo{}) + _, err = db.Db.In("user_identity_id", req.UserIdentityIds).Delete(model.SelfSupportForUserFaceInfo{}) if err != nil { return } diff --git a/app/admin/svc/svc_self_support_for_school.go b/app/admin/svc/svc_self_support_for_school.go new file mode 100644 index 0000000..40126c8 --- /dev/null +++ b/app/admin/svc/svc_self_support_for_school.go @@ -0,0 +1,49 @@ +package svc + +import ( + "applet/app/admin/md" + "applet/app/db" + "applet/app/enum" +) + +func SelfSupportForSchoolInfo(enterpriseId int) (err error, resp md.SelfSupportForSchoolInfoResp) { + //1、查询`enterprise` + enterpriseDb := db.EnterpriseDb{} + enterpriseDb.Set() + enterprise, err := enterpriseDb.GetEnterprise(enterpriseId) + if err != nil { + return + } + resp.Name = enterprise.Name + resp.Memo = enterprise.Memo + resp.Kind = enum.EnterprisePvd(enterprise.Kind).String() + resp.State = enum.EnterpriseState(enterprise.State).String() + + //2、统计 "教师"、 "学生"、 "班级" 数量 + userIdentityDb := db.UserIdentityDb{} + userIdentityDb.Set(0) + resp.StudentNum, err = userIdentityDb.CountUserIdentityForEnterprise(enterpriseId, enum.UserIdentityForCentralKitchenForStudent) + if err != nil { + return + } + resp.TeacherNum, err = userIdentityDb.CountUserIdentityForEnterprise(enterpriseId, enum.UserIdentityForCentralKitchenForTeacher) + if err != nil { + return + } + classDb := db.ClassDb{} + classDb.Set(0) + resp.ClassNum, err = classDb.CountClassForEnterprise(enterpriseId) + if err != nil { + return + } + + //3、统计 用户人脸信息 + selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} + selfSupportForUserFaceInfoDb.Set(0) + resp.SchoolFacePassNum, _ = selfSupportForUserFaceInfoDb.CountSchoolFacePassStatus(enterpriseId, "open") + resp.SchoolFacePaymentNum, _ = selfSupportForUserFaceInfoDb.CountSchoolFacePaymentStatus(enterpriseId, "open") + resp.SingleSchoolFacePassNum, _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(enterpriseId, 1) + resp.ConcentrateSchoolFacePassNum, _ = selfSupportForUserFaceInfoDb.CountCollectFaceType(enterpriseId, 1) + + return +} diff --git a/app/customer/hdl/hdl_user_identity.go b/app/customer/hdl/hdl_user_identity.go index a0d8da5..b7aaf0c 100644 --- a/app/customer/hdl/hdl_user_identity.go +++ b/app/customer/hdl/hdl_user_identity.go @@ -216,6 +216,7 @@ func SaveSelfSupportForSchoolUserIdentity(c *gin.Context) { selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} selfSupportForUserFaceInfoDb.Set(insertAffected) _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoInsert(&model.SelfSupportForUserFaceInfo{ + EnterpriseId: req.EnterpriseId, UserIdentityId: insertAffected, CollectFaceType: 1, SchoolCode: selfSupportForSchoolInfo.SchoolCode, diff --git a/app/customer/hdl/self_support_for_school/hdl_faceCollection.go b/app/customer/hdl/self_support_for_school/hdl_faceCollection.go index 7ad698b..fd7621c 100644 --- a/app/customer/hdl/self_support_for_school/hdl_faceCollection.go +++ b/app/customer/hdl/self_support_for_school/hdl_faceCollection.go @@ -50,7 +50,7 @@ func EducateSceneTokenQuery(c *gin.Context) { StudentName: identity.Name, OutUserId: utils.IntToStr(identity.Id), SchoolStdCode: selfSupportForSchoolInfo.SchoolStdCode, - }, identity.Id, userToken) + }, identity, userToken) if err != nil { e.OutErr(c, e.ERR, err.Error()) return diff --git a/app/customer/svc/svc_curl_smart_pay.go b/app/customer/svc/svc_curl_smart_pay.go index d1069c6..e9612c0 100644 --- a/app/customer/svc/svc_curl_smart_pay.go +++ b/app/customer/svc/svc_curl_smart_pay.go @@ -165,7 +165,7 @@ func CurlAlipayTradeRefund(args md.CurlAlipayTradeRefundReq) (err error, resp in return nil, result.Data } -func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentityId int, userToken string) (err error, resp interface{}) { +func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentity *model.UserIdentity, userToken string) (err error, resp interface{}) { utils.FilePutContents("CurlEducateSceneTokenQuery", utils.SerializeStr(map[string]interface{}{ "args": args, })) @@ -247,7 +247,7 @@ func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentityId } // 更新/新增 `self_support_for_user_facel_info` selfSupportForUserFaceInfoDb := db.SelfSupportForUserFaceInfoDb{} - selfSupportForUserFaceInfoDb.Set(userIdentityId) + selfSupportForUserFaceInfoDb.Set(userIdentity.Id) info, err := selfSupportForUserFaceInfoDb.GetSelfSupportForUserFaceInfo() if err != nil { return @@ -259,7 +259,8 @@ func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentityId if info == nil { info = &model.SelfSupportForUserFaceInfo{ - UserIdentityId: userIdentityId, + EnterpriseId: userIdentity.EnterpriseId, + UserIdentityId: userIdentity.Id, CollectFaceType: 1, SchoolCode: res["school_code"], SchoolStdCode: res["school_std_code"], diff --git a/app/db/db_class.go b/app/db/db_class.go index 923b0d4..2562024 100644 --- a/app/db/db_class.go +++ b/app/db/db_class.go @@ -31,6 +31,14 @@ func (classDb *ClassDb) FindClass() (*[]model.Class, error) { return &m, nil } +func (classDb *ClassDb) FindClassByEnterprise(enterpriseId interface{}) (*[]model.Class, error) { + var m []model.Class + if err := classDb.Db.Desc("id").Where("enterprise_id =?", enterpriseId).Find(&m); err != nil { + return nil, logx.Error(err) + } + return &m, nil +} + func (classDb *ClassDb) ClassDeleteBySession(id interface{}) (int64, error) { if reflect.TypeOf(id).Kind() == reflect.Slice { return classDb.Db.In("id", id).Delete(model.Class{}) diff --git a/app/db/db_permission_group.go b/app/db/db_permission_group.go index f748a9b..05f7510 100644 --- a/app/db/db_permission_group.go +++ b/app/db/db_permission_group.go @@ -1,6 +1,7 @@ package db import ( + "applet/app/admin/enum" "applet/app/db/model" "applet/app/utils/logx" "xorm.io/xorm" @@ -16,7 +17,7 @@ func (permissionGroupDb *PermissionGroupDb) Set() { // set方法 func (permissionGroupDb *PermissionGroupDb) FindPermissionGroup() (*[]model.PermissionGroup, error) { var m []model.PermissionGroup - if err := permissionGroupDb.Db.Asc("id").Find(&m); err != nil { + if err := permissionGroupDb.Db.Where("state = ?", enum.PermissionGroupStateForNormal).Asc("id").Find(&m); err != nil { return nil, logx.Error(err) } return &m, nil diff --git a/app/db/db_self_support_for_user_face_info.go b/app/db/db_self_support_for_user_face_info.go index 2f397f3..34a3059 100644 --- a/app/db/db_self_support_for_user_face_info.go +++ b/app/db/db_self_support_for_user_face_info.go @@ -79,6 +79,33 @@ func (selfSupportForUserFaceInfoDb *SelfSupportForUserFaceInfoDb) SelfSupportFor } } +func (selfSupportForUserFaceInfoDb *SelfSupportForUserFaceInfoDb) CountSchoolFacePassStatus(enterpriseId int, status string) (total int64, err error) { + var m model.SelfSupportForUserFaceInfo + total, err = selfSupportForUserFaceInfoDb.Db.Where("enterprise_id =? AND school_face_pass_status =?", enterpriseId, status).Count(&m) + if err != nil { + return + } + return +} + +func (selfSupportForUserFaceInfoDb *SelfSupportForUserFaceInfoDb) CountSchoolFacePaymentStatus(enterpriseId int, status string) (total int64, err error) { + var m model.SelfSupportForUserFaceInfo + total, err = selfSupportForUserFaceInfoDb.Db.Where("enterprise_id =? AND concentrate_school_face_pass_status =?", enterpriseId, status).Count(&m) + if err != nil { + return + } + return +} + +func (selfSupportForUserFaceInfoDb *SelfSupportForUserFaceInfoDb) CountCollectFaceType(enterpriseId, collectFaceType int) (total int64, err error) { + var m model.SelfSupportForUserFaceInfo + total, err = selfSupportForUserFaceInfoDb.Db.Where("enterprise_id =? AND collect_face_type =?", enterpriseId, collectFaceType).Count(&m) + if err != nil { + return + } + return +} + type SelfSupportForUserFaceInfoWithUserIdentity struct { model.SelfSupportForUserFaceInfo `xorm:"extends"` model.UserIdentity `xorm:"extends"` diff --git a/app/db/model/self_support_for_user_face_info.go b/app/db/model/self_support_for_user_face_info.go index a83d570..26f86a6 100644 --- a/app/db/model/self_support_for_user_face_info.go +++ b/app/db/model/self_support_for_user_face_info.go @@ -2,6 +2,7 @@ package model type SelfSupportForUserFaceInfo struct { Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('单位id') INT(11)"` UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"` CollectFaceType int `json:"collect_face_type" xorm:"not null default 1 comment('采集人脸方式(1:个采 2:集采)') TINYINT(1)"` SchoolCode string `json:"school_code" xorm:"not null default '' comment('学校内标') VARCHAR(255)"`