From c83391f61bb05c4ce2bdf690d01178f314645b09 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Mon, 11 Sep 2023 18:18:03 +0800 Subject: [PATCH] update --- app/admin/hdl/hdl_role.go | 18 ++++++++++ app/admin/md/md_role.go | 5 +++ app/admin/svc/svc_admin_with_enterprise.go | 38 ++++++++++++++++++++++ app/admin/svc/svc_data_statisstics.go | 24 +++++++------- app/router/admin_router.go | 1 + 5 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 app/admin/svc/svc_admin_with_enterprise.go diff --git a/app/admin/hdl/hdl_role.go b/app/admin/hdl/hdl_role.go index f740e35..ba43876 100644 --- a/app/admin/hdl/hdl_role.go +++ b/app/admin/hdl/hdl_role.go @@ -477,6 +477,24 @@ func BindAdminRole(c *gin.Context) { return } +func BindAdminWithEnterprise(c *gin.Context) { + var req md.BindAdminWithEnterpriseReq + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + err = svc.BindAdminWithEnterprise(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, "success", nil) + return +} + func AdminInfo(c *gin.Context) { admId := c.DefaultQuery("adm_id", "") admDb := db.AdminDb{} diff --git a/app/admin/md/md_role.go b/app/admin/md/md_role.go index 445d17b..825132a 100644 --- a/app/admin/md/md_role.go +++ b/app/admin/md/md_role.go @@ -84,3 +84,8 @@ type BindAdminRoleReq struct { AdmId int `json:"adm_id" binding:"required" label:"管理员id"` RoleIds []int `json:"role_ids" label:"角色id"` } + +type BindAdminWithEnterpriseReq struct { + AdmId int `json:"adm_id" binding:"required" label:"管理员id"` + Ids []int `json:"ids" label:"记录id"` +} diff --git a/app/admin/svc/svc_admin_with_enterprise.go b/app/admin/svc/svc_admin_with_enterprise.go new file mode 100644 index 0000000..1b49c88 --- /dev/null +++ b/app/admin/svc/svc_admin_with_enterprise.go @@ -0,0 +1,38 @@ +package svc + +import ( + "applet/app/admin/md" + "applet/app/db" + "applet/app/db/model" +) + +func BindAdminWithEnterprise(req md.BindAdminWithEnterpriseReq) (err error) { + session := db.Db.NewSession() + defer session.Close() + session.Begin() + + //1、删除 `admin_with_enterprise` + adminWithEnterpriseDb := db.AdminWithEnterpriseDb{} + adminWithEnterpriseDb.Set() + _, err = adminWithEnterpriseDb.AdminWithEnterpriseDeleteBySession(session, req.Ids) + if err != nil { + _ = session.Rollback() + return + } + + //2、新增 `admin_with_enterprise`` + var mm []*model.AdminWithEnterprise + for _, v := range req.Ids { + mm = append(mm, &model.AdminWithEnterprise{ + AdmId: req.AdmId, + EnterpriseId: v, + }) + } + _, err = adminWithEnterpriseDb.BatchAddAdminWithEnterpriseBySession(session, mm) + if err != nil { + _ = session.Rollback() + return + } + + return session.Commit() +} diff --git a/app/admin/svc/svc_data_statisstics.go b/app/admin/svc/svc_data_statisstics.go index c42522c..4e87488 100644 --- a/app/admin/svc/svc_data_statisstics.go +++ b/app/admin/svc/svc_data_statisstics.go @@ -1023,17 +1023,19 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD for _, v := range *userIdentities { userIdentityIds = append(userIdentityIds, utils.IntToStr(v.Id)) } - userIdentityStr := php2go.Implode(",", userIdentityIds) - sql2 := fmt.Sprintf("SELECT sum(amount) as total FROM central_kitchen_for_school_user_refund_day where state = %d and identity_id IN (%s) and refund_date >= '%s' and refund_date < '%s'", - enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, userIdentityStr, req.StartDate, req.EndDate) - mapArr2, err := db.QueryNativeString(db.Db, sql2) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - if mapArr2 != nil { - refund = mapArr2[0]["total"] + if len(userIdentityIds) != 0 { + userIdentityStr := php2go.Implode(",", userIdentityIds) + sql2 := fmt.Sprintf("SELECT sum(amount) as total FROM central_kitchen_for_school_user_refund_day where state = %d and identity_id IN (%s) and refund_date >= '%s' and refund_date < '%s'", + enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, userIdentityStr, req.StartDate, req.EndDate) + mapArr2, err := db.QueryNativeString(db.Db, sql2) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return + } + if mapArr2 != nil { + refund = mapArr2[0]["total"] + } } j := 2 //表头被第一行用了,只能从第二行开始 xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Name, income, refund}) diff --git a/app/router/admin_router.go b/app/router/admin_router.go index bc934af..605b4a9 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -244,6 +244,7 @@ func rRole(r *gin.RouterGroup) { r.DELETE("/deleteAdmin/:adm_id", hdl2.DeleteAdmin) //删除管理员 r.GET("/adminInfo", hdl2.AdminInfo) //获取管理员信息 r.POST("/bindAdminRole", hdl2.BindAdminRole) //绑定角色 + r.POST("/bindAdminWithEnterprise", hdl2.BindAdminWithEnterprise) //绑定校企 } func AdminRoute(r *gin.RouterGroup) {