126 lines
4.1 KiB
Go
126 lines
4.1 KiB
Go
// 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"
|
|
"strings"
|
|
|
|
"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
|
|
}
|
|
|
|
where, args := s.buildWhere(in)
|
|
totalValue, err := g.DB().GetValue(ctx, "SELECT COUNT(*) FROM im_tenant_applications "+where, args...)
|
|
if err != nil {
|
|
return nil, 0, gerror.Wrap(err, "获取企业注册申请总数失败,请稍后重试!")
|
|
}
|
|
totalCount = totalValue.Int()
|
|
|
|
page, perPage := normalizePage(in.Page, in.PerPage)
|
|
query := `SELECT id,application_id,credit_code,enterprise_email,license_file_id,tenant_code_hint,
|
|
status,estimated_review_hour,submitted_at,created_at,updated_at
|
|
FROM im_tenant_applications ` + where + ` ORDER BY created_at DESC,id DESC LIMIT ? OFFSET ?`
|
|
queryArgs := append(append([]any{}, args...), perPage, (page-1)*perPage)
|
|
rows, err := g.DB().GetAll(ctx, query, queryArgs...)
|
|
if err != nil {
|
|
return nil, 0, gerror.Wrap(err, "获取企业注册申请列表失败,请稍后重试!")
|
|
}
|
|
if err = rows.Structs(&list); err != nil {
|
|
return nil, 0, gerror.Wrap(err, "解析企业注册申请列表失败,请稍后重试!")
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *sSysImTenantApplication) buildWhere(in *sysin.ImTenantApplicationListInp) (string, []any) {
|
|
parts := []string{"1=1"}
|
|
args := []any{}
|
|
if in.ApplicationId != "" {
|
|
parts = append(parts, "application_id LIKE ?")
|
|
args = append(args, "%"+in.ApplicationId+"%")
|
|
}
|
|
if in.CreditCode != "" {
|
|
parts = append(parts, "credit_code LIKE ?")
|
|
args = append(args, "%"+in.CreditCode+"%")
|
|
}
|
|
if in.EnterpriseEmail != "" {
|
|
parts = append(parts, "enterprise_email LIKE ?")
|
|
args = append(args, "%"+in.EnterpriseEmail+"%")
|
|
}
|
|
if in.TenantCodeHint != "" {
|
|
parts = append(parts, "tenant_code_hint LIKE ?")
|
|
args = append(args, "%"+in.TenantCodeHint+"%")
|
|
}
|
|
if in.Status != "" {
|
|
parts = append(parts, "status=?")
|
|
args = append(args, in.Status)
|
|
}
|
|
if in.Keyword != "" {
|
|
like := "%" + in.Keyword + "%"
|
|
parts = append(parts, "(application_id LIKE ? OR credit_code LIKE ? OR enterprise_email LIKE ? OR tenant_code_hint LIKE ?)")
|
|
args = append(args, like, like, like, like)
|
|
}
|
|
if len(in.CreatedAt) == 2 {
|
|
parts = append(parts, "created_at BETWEEN ? AND ?")
|
|
args = append(args, in.CreatedAt[0], in.CreatedAt[1])
|
|
}
|
|
return "WHERE " + strings.Join(parts, " AND "), args
|
|
}
|
|
|
|
// View 获取企业注册申请指定信息
|
|
func (s *sSysImTenantApplication) View(ctx context.Context, in *sysin.ImTenantApplicationViewInp) (res *sysin.ImTenantApplicationViewModel, err error) {
|
|
if err = in.Filter(ctx); err != nil {
|
|
return
|
|
}
|
|
|
|
query := `SELECT 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 FROM im_tenant_applications WHERE id=? LIMIT 1`
|
|
row, err := g.DB().GetOne(ctx, query, in.Id)
|
|
if err != nil {
|
|
return nil, gerror.Wrap(err, "获取企业注册申请信息失败,请稍后重试!")
|
|
}
|
|
if row.IsEmpty() {
|
|
return nil, nil
|
|
}
|
|
if err = row.Struct(&res); err != nil {
|
|
return nil, gerror.Wrap(err, "解析企业注册申请信息失败,请稍后重试!")
|
|
}
|
|
if res == nil {
|
|
return
|
|
}
|
|
res.LicenseFile, err = firstImPublicUpload(ctx, res.LicenseFileId)
|
|
return
|
|
}
|
|
|
|
func normalizePage(page, perPage int) (int, int) {
|
|
if page <= 0 {
|
|
page = 1
|
|
}
|
|
if perPage <= 0 {
|
|
perPage = 20
|
|
}
|
|
return page, perPage
|
|
}
|