feat: add tenant entry application pages

This commit is contained in:
richjohnrambo
2026-09-22 23:17:55 +08:00
parent 935bfe17a0
commit abd5eb162a
22 changed files with 1447 additions and 55 deletions
@@ -0,0 +1,90 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2026 HotGo
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys
import (
"context"
"hotgo/internal/library/storager"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"strings"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
func loadImPublicUploads(ctx context.Context, fileIds []string) (files []*sysin.ImPublicUploadModel, err error) {
fileIds = compactStringSlice(fileIds)
if len(fileIds) == 0 {
return []*sysin.ImPublicUploadModel{}, nil
}
if err = g.DB().Model("im_public_uploads").Safe().Ctx(ctx).
Fields(
"id",
"file_id",
"purpose",
"mime_type",
"size",
"etag",
"location",
"expires_at",
"created_at",
"uploaded_at",
).
WhereIn("file_id", fileIds).
OrderAsc("id").
Scan(&files); err != nil {
return nil, gerror.Wrap(err, "获取公共上传文件信息失败,请稍后重试!")
}
drive := ""
if conf, confErr := service.SysConfig().GetUpload(ctx); confErr == nil && conf != nil {
drive = conf.Drive
}
for _, file := range files {
file.Url = storager.LastUrl(ctx, file.Location, drive)
}
return
}
func firstImPublicUpload(ctx context.Context, fileId string) (file *sysin.ImPublicUploadModel, err error) {
files, err := loadImPublicUploads(ctx, []string{fileId})
if err != nil || len(files) == 0 {
return
}
return files[0], nil
}
func parseJSONStringSlice(raw string) []string {
raw = strings.TrimSpace(raw)
if raw == "" || raw == "null" {
return nil
}
var ids []string
if err := gjson.DecodeTo([]byte(raw), &ids); err == nil && len(ids) > 0 {
return compactStringSlice(ids)
}
return compactStringSlice([]string{raw})
}
func compactStringSlice(values []string) []string {
res := make([]string, 0, len(values))
seen := make(map[string]struct{}, len(values))
for _, value := range values {
value = strings.TrimSpace(value)
if value == "" {
continue
}
if _, ok := seen[value]; ok {
continue
}
seen[value] = struct{}{}
res = append(res, value)
}
return res
}
@@ -0,0 +1,117 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2026 HotGo
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys
import (
"context"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
type sSysImTenantApplication struct{}
func NewSysImTenantApplication() *sSysImTenantApplication {
return &sSysImTenantApplication{}
}
func init() {
service.RegisterSysImTenantApplication(NewSysImTenantApplication())
}
// List 获取企业注册申请列表
func (s *sSysImTenantApplication) List(ctx context.Context, in *sysin.ImTenantApplicationListInp) (list []*sysin.ImTenantApplicationListModel, totalCount int, err error) {
if err = in.Filter(ctx); err != nil {
return
}
mod := s.listModel(ctx)
mod = s.applyWhere(mod, in)
mod = mod.Page(in.Page, in.PerPage).OrderDesc("created_at").OrderDesc("id")
if err = mod.ScanAndCount(&list, &totalCount, false); err != nil {
return nil, 0, gerror.Wrap(err, "获取企业注册申请列表失败,请稍后重试!")
}
return
}
func (s *sSysImTenantApplication) listModel(ctx context.Context) *gdb.Model {
return g.DB().Model("im_tenant_applications").Safe().Ctx(ctx).Fields(
"id",
"application_id",
"credit_code",
"enterprise_email",
"license_file_id",
"tenant_code_hint",
"status",
"estimated_review_hour",
"submitted_at",
"created_at",
"updated_at",
)
}
func (s *sSysImTenantApplication) applyWhere(mod *gdb.Model, in *sysin.ImTenantApplicationListInp) *gdb.Model {
if in.ApplicationId != "" {
mod = mod.WhereLike("application_id", "%"+in.ApplicationId+"%")
}
if in.CreditCode != "" {
mod = mod.WhereLike("credit_code", "%"+in.CreditCode+"%")
}
if in.EnterpriseEmail != "" {
mod = mod.WhereLike("enterprise_email", "%"+in.EnterpriseEmail+"%")
}
if in.TenantCodeHint != "" {
mod = mod.WhereLike("tenant_code_hint", "%"+in.TenantCodeHint+"%")
}
if in.Status != "" {
mod = mod.Where("status", in.Status)
}
if in.Keyword != "" {
like := "%" + in.Keyword + "%"
mod = mod.Where("(application_id LIKE ? OR credit_code LIKE ? OR enterprise_email LIKE ? OR tenant_code_hint LIKE ?)", like, like, like, like)
}
if len(in.CreatedAt) == 2 {
mod = mod.WhereBetween("created_at", in.CreatedAt[0], in.CreatedAt[1])
}
return mod
}
// View 获取企业注册申请指定信息
func (s *sSysImTenantApplication) View(ctx context.Context, in *sysin.ImTenantApplicationViewInp) (res *sysin.ImTenantApplicationViewModel, err error) {
if err = in.Filter(ctx); err != nil {
return
}
if err = g.DB().Model("im_tenant_applications").Safe().Ctx(ctx).
Fields(
"id",
"application_id",
"credit_code",
"enterprise_email",
"license_file_id",
"tenant_code_hint",
"CAST(client_context AS CHAR) client_context",
"idempotency_key",
"status",
"estimated_review_hour",
"submitted_at",
"created_at",
"updated_at",
).
Where("id", in.Id).
Scan(&res); err != nil {
return nil, gerror.Wrap(err, "获取企业注册申请信息失败,请稍后重试!")
}
if res == nil {
return
}
res.LicenseFile, err = firstImPublicUpload(ctx, res.LicenseFileId)
return
}
@@ -0,0 +1,111 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2026 HotGo
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys
import (
"context"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
type sSysImTenantEntryFeedback struct{}
func NewSysImTenantEntryFeedback() *sSysImTenantEntryFeedback {
return &sSysImTenantEntryFeedback{}
}
func init() {
service.RegisterSysImTenantEntryFeedback(NewSysImTenantEntryFeedback())
}
// List 获取企业入口反馈列表
func (s *sSysImTenantEntryFeedback) List(ctx context.Context, in *sysin.ImTenantEntryFeedbackListInp) (list []*sysin.ImTenantEntryFeedbackListModel, totalCount int, err error) {
if err = in.Filter(ctx); err != nil {
return
}
mod := s.listModel(ctx)
mod = s.applyWhere(mod, in)
mod = mod.Page(in.Page, in.PerPage).OrderDesc("created_at").OrderDesc("id")
if err = mod.ScanAndCount(&list, &totalCount, false); err != nil {
return nil, 0, gerror.Wrap(err, "获取企业入口反馈列表失败,请稍后重试!")
}
return
}
func (s *sSysImTenantEntryFeedback) listModel(ctx context.Context) *gdb.Model {
return g.DB().Model("im_tenant_entry_feedbacks").Safe().Ctx(ctx).Fields(
"id",
"feedback_id",
"description",
"contact",
"tenant_code_hint",
"status",
"submitted_at",
"created_at",
"updated_at",
)
}
func (s *sSysImTenantEntryFeedback) applyWhere(mod *gdb.Model, in *sysin.ImTenantEntryFeedbackListInp) *gdb.Model {
if in.FeedbackId != "" {
mod = mod.WhereLike("feedback_id", "%"+in.FeedbackId+"%")
}
if in.Contact != "" {
mod = mod.WhereLike("contact", "%"+in.Contact+"%")
}
if in.TenantCodeHint != "" {
mod = mod.WhereLike("tenant_code_hint", "%"+in.TenantCodeHint+"%")
}
if in.Status != "" {
mod = mod.Where("status", in.Status)
}
if in.Keyword != "" {
like := "%" + in.Keyword + "%"
mod = mod.Where("(feedback_id LIKE ? OR description LIKE ? OR contact LIKE ? OR tenant_code_hint LIKE ?)", like, like, like, like)
}
if len(in.CreatedAt) == 2 {
mod = mod.WhereBetween("created_at", in.CreatedAt[0], in.CreatedAt[1])
}
return mod
}
// View 获取企业入口反馈指定信息
func (s *sSysImTenantEntryFeedback) View(ctx context.Context, in *sysin.ImTenantEntryFeedbackViewInp) (res *sysin.ImTenantEntryFeedbackViewModel, err error) {
if err = in.Filter(ctx); err != nil {
return
}
if err = g.DB().Model("im_tenant_entry_feedbacks").Safe().Ctx(ctx).
Fields(
"id",
"feedback_id",
"description",
"contact",
"tenant_code_hint",
"CAST(screenshot_file_ids AS CHAR) screenshot_file_ids",
"CAST(client_context AS CHAR) client_context",
"idempotency_key",
"status",
"submitted_at",
"created_at",
"updated_at",
).
Where("id", in.Id).
Scan(&res); err != nil {
return nil, gerror.Wrap(err, "获取企业入口反馈信息失败,请稍后重试!")
}
if res == nil {
return
}
res.ScreenshotFiles, err = loadImPublicUploads(ctx, parseJSONStringSlice(res.ScreenshotFileIds))
return
}