初始化项目
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidService/model/dto"
|
||||
"cidService/model/entity"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"context"
|
||||
|
||||
"gitee.com/red-future---jilin-g/common/http"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidService/model/entity"
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/model/entity"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidService/model/dto"
|
||||
"cidService/model/entity"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidService/model/dto"
|
||||
"cidService/model/entity"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
97
dao/application_dao.go
Normal file
97
dao/application_dao.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// applicationDao 应用DAO
|
||||
type applicationDao struct{}
|
||||
|
||||
var Application = &applicationDao{}
|
||||
|
||||
// Ctx 获取数据库上下文
|
||||
func (d *applicationDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return g.DB().Model("application").Ctx(ctx)
|
||||
}
|
||||
|
||||
// Create 创建应用
|
||||
func (d *applicationDao) Create(ctx context.Context, app *entity.Application) (int64, error) {
|
||||
result, err := d.Ctx(ctx).Insert(app)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
id, _ := result.LastInsertId()
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取应用
|
||||
func (d *applicationDao) GetByID(ctx context.Context, id int64) (*entity.Application, error) {
|
||||
var app *entity.Application
|
||||
err := d.Ctx(ctx).Where("id", id).Scan(&app)
|
||||
return app, err
|
||||
}
|
||||
|
||||
// GetByTenantID 根据租户ID获取应用列表
|
||||
func (d *applicationDao) GetByTenantID(ctx context.Context, tenantID int64) ([]*entity.Application, error) {
|
||||
var apps []*entity.Application
|
||||
err := d.Ctx(ctx).Where("tenant_id", tenantID).Scan(&apps)
|
||||
return apps, err
|
||||
}
|
||||
|
||||
// GetByAPIKey 根据API密钥获取应用
|
||||
func (d *applicationDao) GetByAPIKey(ctx context.Context, apiKey string) (*entity.Application, error) {
|
||||
var app *entity.Application
|
||||
err := d.Ctx(ctx).Where("app_key", apiKey).Scan(&app)
|
||||
return app, err
|
||||
}
|
||||
|
||||
// Update 更新应用
|
||||
func (d *applicationDao) Update(ctx context.Context, app *entity.Application) error {
|
||||
_, err := d.Ctx(ctx).Where("id", app.Id).Update(app)
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 删除应用
|
||||
func (d *applicationDao) Delete(ctx context.Context, id int64) error {
|
||||
_, err := d.Ctx(ctx).Where("id", id).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
// List 应用列表
|
||||
func (d *applicationDao) List(ctx context.Context, tenantID int64, page, pageSize int) ([]*entity.Application, int, error) {
|
||||
model := d.Ctx(ctx)
|
||||
if tenantID > 0 {
|
||||
model = model.Where("tenant_id", tenantID)
|
||||
}
|
||||
|
||||
var apps []*entity.Application
|
||||
err := model.Page(page, pageSize).OrderDesc("created_at").Scan(&apps)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return apps, total, nil
|
||||
}
|
||||
|
||||
// GetByName 根据名称获取应用
|
||||
func (d *applicationDao) GetByName(ctx context.Context, name string) (*entity.Application, error) {
|
||||
var app *entity.Application
|
||||
err := d.Ctx(ctx).Where("name", name).Scan(&app)
|
||||
return app, err
|
||||
}
|
||||
|
||||
// UpdateFields 更新应用部分字段
|
||||
func (d *applicationDao) UpdateFields(ctx context.Context, id int64, data *entity.Application) error {
|
||||
_, err := d.Ctx(ctx).Where("id", id).Update(data)
|
||||
return err
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidService/model/entity"
|
||||
"cidservice/model/entity"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@@ -3,8 +3,8 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidService/model/dto"
|
||||
"cidService/model/entity"
|
||||
"cidservice/model/dto"
|
||||
"cidservice/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
90
dao/stat_report_dao.go
Normal file
90
dao/stat_report_dao.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// statReportDao 统计报表DAO
|
||||
type statReportDao struct{}
|
||||
|
||||
var StatReport = &statReportDao{}
|
||||
|
||||
// Ctx 获取数据库上下文
|
||||
func (d *statReportDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return g.DB().Model("stat_report").Ctx(ctx)
|
||||
}
|
||||
|
||||
// Create 创建统计报表
|
||||
func (d *statReportDao) Create(ctx context.Context, report *entity.StatReport) (int64, error) {
|
||||
result, err := d.Ctx(ctx).Insert(report)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
id, _ := result.LastInsertId()
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取统计报表
|
||||
func (d *statReportDao) GetByID(ctx context.Context, id int64) (*entity.StatReport, error) {
|
||||
var report *entity.StatReport
|
||||
err := d.Ctx(ctx).Where("id", id).Scan(&report)
|
||||
return report, err
|
||||
}
|
||||
|
||||
// GetByTenantAndDate 根据租户和日期获取统计报表
|
||||
func (d *statReportDao) GetByTenantAndDate(ctx context.Context, tenantID int64, reportType, date string) (*entity.StatReport, error) {
|
||||
var report *entity.StatReport
|
||||
err := d.Ctx(ctx).Where("tenant_id", tenantID).Where("report_type", reportType).Where("report_date", date).Scan(&report)
|
||||
return report, err
|
||||
}
|
||||
|
||||
// Update 更新统计报表
|
||||
func (d *statReportDao) Update(ctx context.Context, report *entity.StatReport) error {
|
||||
_, err := d.Ctx(ctx).Where("id", report.Id).Update(report)
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete 删除统计报表
|
||||
func (d *statReportDao) Delete(ctx context.Context, id int64) error {
|
||||
_, err := d.Ctx(ctx).Where("id", id).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
// List 统计报表列表
|
||||
func (d *statReportDao) List(ctx context.Context, tenantID, appID int64, reportType, startDate, endDate string, page, pageSize int) ([]*entity.StatReport, int, error) {
|
||||
model := d.Ctx(ctx)
|
||||
|
||||
if tenantID > 0 {
|
||||
model = model.Where("tenant_id", tenantID)
|
||||
}
|
||||
if appID > 0 {
|
||||
model = model.Where("app_id", appID)
|
||||
}
|
||||
if reportType != "" {
|
||||
model = model.Where("report_type", reportType)
|
||||
}
|
||||
if startDate != "" {
|
||||
model = model.WhereGTE("report_date", startDate)
|
||||
}
|
||||
if endDate != "" {
|
||||
model = model.WhereLTE("report_date", endDate)
|
||||
}
|
||||
|
||||
var reports []*entity.StatReport
|
||||
err := model.Page(page, pageSize).OrderDesc("generated_at").Scan(&reports)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return reports, total, nil
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"cidService/model/entity"
|
||||
"cidservice/model/entity"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
79
dao/tenant_dao.go
Normal file
79
dao/tenant_dao.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cidservice/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
var Tenant = tenantDao{}
|
||||
|
||||
type tenantDao struct{}
|
||||
|
||||
// Create 创建租户
|
||||
func (d *tenantDao) Create(ctx context.Context, tenant *entity.Tenant) (id int64, err error) {
|
||||
result, err := g.DB().Model("tenant").Ctx(ctx).Insert(tenant)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
id, _ = result.LastInsertId()
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取租户
|
||||
func (d *tenantDao) GetByID(ctx context.Context, id int64) (tenant *entity.Tenant, err error) {
|
||||
err = g.DB().Model("tenant").Ctx(ctx).Where("id = ? AND is_deleted = ?", id, false).Scan(&tenant)
|
||||
return
|
||||
}
|
||||
|
||||
// GetByCode 根据编码获取租户
|
||||
func (d *tenantDao) GetByCode(ctx context.Context, code string) (tenant *entity.Tenant, err error) {
|
||||
err = g.DB().Model("tenant").Ctx(ctx).Where("code = ? AND is_deleted = ?", code, false).Scan(&tenant)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateFields 更新租户字段
|
||||
func (d *tenantDao) UpdateFields(ctx context.Context, id int64, updateData *entity.Tenant) (affected int64, err error) {
|
||||
result, err := g.DB().Model("tenant").Ctx(ctx).Where("id = ? AND is_deleted = ?", id, false).Update(updateData)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
// Delete 删除租户
|
||||
func (d *tenantDao) Delete(ctx context.Context, id int64) (affected int64, err error) {
|
||||
result, err := g.DB().Model("tenant").Ctx(ctx).Where("id = ?", id).Update(gdb.Map{"is_deleted": true})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
rowsAffected, _ := result.RowsAffected()
|
||||
return rowsAffected, nil
|
||||
}
|
||||
|
||||
// List 获取租户列表
|
||||
func (d *tenantDao) List(ctx context.Context, page, size int, filter map[string]interface{}) (list []*entity.Tenant, total int64, err error) {
|
||||
model := g.DB().Model("tenant").Ctx(ctx).Where("is_deleted = ?", false)
|
||||
|
||||
// 应用过滤条件
|
||||
if filter != nil {
|
||||
for key, value := range filter {
|
||||
model = model.Where(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
count, err := model.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
total = int64(count)
|
||||
|
||||
// 分页查询
|
||||
err = model.Page(page, size).OrderDesc("created_at").Scan(&list)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user