代码初始化
This commit is contained in:
86
dao/copydata/api_account_report_detail_dao.go
Normal file
86
dao/copydata/api_account_report_detail_dao.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var CidAccountReportDetail = new(cidAccountReportDetailDao)
|
||||
|
||||
type cidAccountReportDetailDao struct{}
|
||||
|
||||
// Insert 插入广告数据报表详情
|
||||
func (d *cidAccountReportDetailDao) Insert(ctx context.Context, req *dto.CidAccountReportDetailItem) (id int64, err error) {
|
||||
var entityData *entity.CidAccountReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.CidAccountReportDetailTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入广告数据报表详情
|
||||
func (d *cidAccountReportDetailDao) BatchInsert(ctx context.Context, reqs []*dto.CidAccountReportDetailItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
// 分批处理,每批100条
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.CidAccountReportDetail, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.CidAccountReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行批量插入
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.CidAccountReportDetailTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
// 批量插入失败,尝试逐条插入
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
86
dao/copydata/api_account_report_sum_dao.go
Normal file
86
dao/copydata/api_account_report_sum_dao.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var CidAccountReportSum = new(CidAccountReportSumDao)
|
||||
|
||||
type CidAccountReportSumDao struct{}
|
||||
|
||||
// Insert 插入广告数据报表详情
|
||||
func (d *CidAccountReportSumDao) Insert(ctx context.Context, req *dto.CidAccountReportSumItem) (id int64, err error) {
|
||||
var entityData *entity.CidAccountReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.CidAccountReportSumTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入广告数据报表详情
|
||||
func (d *CidAccountReportSumDao) BatchInsert(ctx context.Context, reqs []*dto.CidAccountReportSumItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
// 分批处理,每批100条
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.CidAccountReportSum, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.CidAccountReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行批量插入
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.CidAccountReportSumTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
// 批量插入失败,尝试逐条插入
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
81
dao/copydata/creative_report_detail_dao.go
Normal file
81
dao/copydata/creative_report_detail_dao.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var CreativeReportDetail = new(CreativeReportDetailDao)
|
||||
|
||||
type CreativeReportDetailDao struct{}
|
||||
|
||||
func (d *CreativeReportDetailDao) Insert(ctx context.Context, req *dto.CreativeReportDetailItem) (id int64, err error) {
|
||||
var entityData *entity.CreativeReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.CreativeReportDetailTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
func (d *CreativeReportDetailDao) BatchInsert(ctx context.Context, reqs []*dto.CreativeReportDetailItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.CreativeReportDetail, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.CreativeReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.CreativeReportDetailTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
86
dao/copydata/creative_report_sum_dao.go
Normal file
86
dao/copydata/creative_report_sum_dao.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var CreativeReportSum = new(CreativeReportSumDao)
|
||||
|
||||
type CreativeReportSumDao struct{}
|
||||
|
||||
// Insert 插入广告效果指标表
|
||||
func (d *CreativeReportSumDao) Insert(ctx context.Context, req *dto.CreativeReportSumItem) (id int64, err error) {
|
||||
var entityData *entity.CreativeReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.CreativeReportSumTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入广告效果指标表
|
||||
func (d *CreativeReportSumDao) BatchInsert(ctx context.Context, reqs []*dto.CreativeReportSumItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
// 分批处理,每批 100 条
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.CreativeReportSum, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.CreativeReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行批量插入
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.CreativeReportSumTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
// 批量插入失败,尝试逐条插入
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
128
dao/copydata/material_report_dao.go
Normal file
128
dao/copydata/material_report_dao.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var MaterialReport = new(materialReportDao)
|
||||
|
||||
type materialReportDao struct{}
|
||||
|
||||
// Insert 插入素材报表数据
|
||||
func (d *materialReportDao) Insert(ctx context.Context, req *dto.MaterialReportItem) (id int64, err error) {
|
||||
var entityData *entity.MaterialReport
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.MaterialReportTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入素材报表数据
|
||||
func (d *materialReportDao) BatchInsert(ctx context.Context, reqs []*dto.MaterialReportItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.MaterialReport, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.MaterialReport
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.MaterialReportTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
|
||||
// List 查询素材报表数据列表
|
||||
func (d *materialReportDao) List(ctx context.Context, req *dto.ListMaterialReportReq) ([]*entity.MaterialReport, int, error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.MaterialReportTable).Model
|
||||
|
||||
if req.ReportDateStr != "" {
|
||||
model = model.Where("report_date_str", req.ReportDateStr)
|
||||
}
|
||||
if req.PhotoId != "" {
|
||||
model = model.Where("photo_id", req.PhotoId)
|
||||
}
|
||||
if req.CampaignId != nil {
|
||||
model = model.Where("campaign_id", req.CampaignId)
|
||||
}
|
||||
if req.UnitId != nil {
|
||||
model = model.Where("unit_id", req.UnitId)
|
||||
}
|
||||
if req.CreativeId != nil {
|
||||
model = model.Where("creative_id", req.CreativeId)
|
||||
}
|
||||
if req.Keyword != "" {
|
||||
model = model.Where("(photo_name LIKE ? OR campaign_name LIKE ? OR unit_name LIKE ? OR creative_name LIKE ?)",
|
||||
"%"+req.Keyword+"%", "%"+req.Keyword+"%", "%"+req.Keyword+"%", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
model = model.OrderDesc("created_at")
|
||||
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var list []*entity.MaterialReport
|
||||
if req.Page != nil {
|
||||
err = model.Page(int(req.Page.PageNum), int(req.Page.PageSize)).Scan(&list)
|
||||
} else {
|
||||
err = model.Scan(&list)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return list, total, nil
|
||||
}
|
||||
124
dao/copydata/population_report_dao.go
Normal file
124
dao/copydata/population_report_dao.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var PopulationReport = new(populationReportDao)
|
||||
|
||||
type populationReportDao struct{}
|
||||
|
||||
// Insert 插入人群报表数据
|
||||
func (d *populationReportDao) Insert(ctx context.Context, req *dto.PopulationReportItem) (id int64, err error) {
|
||||
var entityData *entity.PopulationReport
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.PopulationReportTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入人群报表数据
|
||||
func (d *populationReportDao) BatchInsert(ctx context.Context, reqs []*dto.PopulationReportItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
// 分批处理,每批 100 条
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.PopulationReport, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.PopulationReport
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行批量插入
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.PopulationReportTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
// 批量插入失败,尝试逐条插入
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
|
||||
// List 查询人群报表数据列表
|
||||
func (d *populationReportDao) List(ctx context.Context, req *dto.ListPopulationReportReq) ([]*entity.PopulationReport, int, error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.PopulationReportTable).Model
|
||||
|
||||
// 构建查询条件
|
||||
if req.ReportDateStr != "" {
|
||||
model = model.Where("report_date_str", req.ReportDateStr)
|
||||
}
|
||||
if req.PhotoId != "" {
|
||||
model = model.Where("photo_id", req.PhotoId)
|
||||
}
|
||||
if req.Keyword != "" {
|
||||
model = model.Where("photo_name LIKE ?", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
// 设置排序
|
||||
model = model.OrderDesc("created_at")
|
||||
|
||||
// 分页查询并获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var list []*entity.PopulationReport
|
||||
if req.Page != nil {
|
||||
err = model.Page(int(req.Page.PageNum), int(req.Page.PageSize)).Scan(&list)
|
||||
} else {
|
||||
err = model.Scan(&list)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return list, total, nil
|
||||
}
|
||||
86
dao/copydata/storewide_report_detail_dao.go
Normal file
86
dao/copydata/storewide_report_detail_dao.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var StorewideReportDetail = new(StorewideReportDetailDao)
|
||||
|
||||
type StorewideReportDetailDao struct{}
|
||||
|
||||
// Insert 插入广告效果指标表
|
||||
func (d *StorewideReportDetailDao) Insert(ctx context.Context, req *dto.StorewideReportDetailItem) (id int64, err error) {
|
||||
var entityData *entity.StorewideReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.StorewideReportDetailTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入广告效果指标表
|
||||
func (d *StorewideReportDetailDao) BatchInsert(ctx context.Context, reqs []*dto.StorewideReportDetailItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
// 分批处理,每批 100 条
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.StorewideReportDetail, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.StorewideReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行批量插入
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.StorewideReportDetailTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
// 批量插入失败,尝试逐条插入
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
86
dao/copydata/storewide_report_sum_dao.go
Normal file
86
dao/copydata/storewide_report_sum_dao.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var StorewideReportSum = new(StorewideReportSumDao)
|
||||
|
||||
type StorewideReportSumDao struct{}
|
||||
|
||||
// Insert 插入广告效果指标表
|
||||
func (d *StorewideReportSumDao) Insert(ctx context.Context, req *dto.StorewideReportSumItem) (id int64, err error) {
|
||||
var entityData *entity.StorewideReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.StorewideReportSumTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入广告效果指标表
|
||||
func (d *StorewideReportSumDao) BatchInsert(ctx context.Context, reqs []*dto.StorewideReportSumItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
// 分批处理,每批 100 条
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.StorewideReportSum, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.StorewideReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行批量插入
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.StorewideReportSumTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
// 批量插入失败,尝试逐条插入
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
124
dao/copydata/task_report_dao.go
Normal file
124
dao/copydata/task_report_dao.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var TaskReport = new(taskReportDao)
|
||||
|
||||
type taskReportDao struct{}
|
||||
|
||||
// Insert 插入调控任务数据
|
||||
func (d *taskReportDao) Insert(ctx context.Context, req *dto.TaskReportItem) (id int64, err error) {
|
||||
var entityData *entity.TaskReport
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.TaskReportTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入调控任务数据
|
||||
func (d *taskReportDao) BatchInsert(ctx context.Context, reqs []*dto.TaskReportItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
// 分批处理,每批 100 条
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.TaskReport, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.TaskReport
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 执行批量插入
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.TaskReportTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
// 批量插入失败,尝试逐条插入
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
|
||||
// List 查询调控任务数据列表
|
||||
func (d *taskReportDao) List(ctx context.Context, req *dto.ListTaskReportReq) ([]*entity.TaskReport, int, error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, consts.TaskReportTable).Model
|
||||
|
||||
// 构建查询条件
|
||||
if req.ReportDateStr != "" {
|
||||
model = model.Where("report_date_str", req.ReportDateStr)
|
||||
}
|
||||
if req.PhotoId != "" {
|
||||
model = model.Where("photo_id", req.PhotoId)
|
||||
}
|
||||
if req.Keyword != "" {
|
||||
model = model.Where("photo_name LIKE ?", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
// 设置排序
|
||||
model = model.OrderDesc("created_at")
|
||||
|
||||
// 分页查询并获取总数
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var list []*entity.TaskReport
|
||||
if req.Page != nil {
|
||||
err = model.Page(int(req.Page.PageNum), int(req.Page.PageSize)).Scan(&list)
|
||||
} else {
|
||||
err = model.Scan(&list)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return list, total, nil
|
||||
}
|
||||
83
dao/copydata/unit_report_detail_dao.go
Normal file
83
dao/copydata/unit_report_detail_dao.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var UnitReportDetail = new(UnitReportDetailDao)
|
||||
|
||||
type UnitReportDetailDao struct{}
|
||||
|
||||
// Insert 插入广告效果指标详情
|
||||
func (d *UnitReportDetailDao) Insert(ctx context.Context, req *dto.UnitReportDetailItem) (id int64, err error) {
|
||||
var entityData *entity.UnitReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.UnitReportDetailTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入广告效果指标详情
|
||||
func (d *UnitReportDetailDao) BatchInsert(ctx context.Context, reqs []*dto.UnitReportDetailItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.UnitReportDetail, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.UnitReportDetail
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.UnitReportDetailTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
83
dao/copydata/unit_report_sum_dao.go
Normal file
83
dao/copydata/unit_report_sum_dao.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
consts "cid/consts/public"
|
||||
dto "cid/model/dto/copydata"
|
||||
entity "cid/model/entity/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var UnitReportSum = new(UnitReportSumDao)
|
||||
|
||||
type UnitReportSumDao struct{}
|
||||
|
||||
// Insert 插入广告效果指标
|
||||
func (d *UnitReportSumDao) Insert(ctx context.Context, req *dto.UnitReportSumItem) (id int64, err error) {
|
||||
var entityData *entity.UnitReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.UnitReportSumTable).Data(&entityData).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// BatchInsert 批量插入广告效果指标
|
||||
func (d *UnitReportSumDao) BatchInsert(ctx context.Context, reqs []*dto.UnitReportSumItem) (successCount int64, failCount int64, failedIndexes []int64, err error) {
|
||||
if len(reqs) == 0 {
|
||||
return 0, 0, nil, errors.New("批量插入数据不能为空")
|
||||
}
|
||||
|
||||
batchSize := 100
|
||||
successCount = 0
|
||||
failCount = 0
|
||||
failedIndexes = make([]int64, 0)
|
||||
|
||||
for i := 0; i < len(reqs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(reqs) {
|
||||
end = len(reqs)
|
||||
}
|
||||
|
||||
batch := reqs[i:end]
|
||||
entityList := make([]*entity.UnitReportSum, len(batch))
|
||||
|
||||
for j, req := range batch {
|
||||
var entityData entity.UnitReportSum
|
||||
if err = gconv.Struct(req, &entityData); err != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+j))
|
||||
continue
|
||||
}
|
||||
entityList[j] = &entityData
|
||||
}
|
||||
|
||||
if len(entityList) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = gfdb.DB(ctx).Model(ctx, consts.UnitReportSumTable).Data(entityList).Insert()
|
||||
if err != nil {
|
||||
for k := range batch {
|
||||
_, singleErr := d.Insert(ctx, batch[k])
|
||||
if singleErr != nil {
|
||||
failCount++
|
||||
failedIndexes = append(failedIndexes, int64(i+k))
|
||||
} else {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
successCount += int64(len(entityList))
|
||||
}
|
||||
}
|
||||
|
||||
return successCount, failCount, failedIndexes, nil
|
||||
}
|
||||
Reference in New Issue
Block a user