批量新增 获取广告计划数据
This commit is contained in:
97
service/copydata/campaign_report_service.go
Normal file
97
service/copydata/campaign_report_service.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package copydata
|
||||
|
||||
import (
|
||||
dao "cid/dao/copydata"
|
||||
dto "cid/model/dto/copydata"
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type campaignReportSumService struct{}
|
||||
|
||||
// CampaignReportSum 广告计划效果指标表服务
|
||||
var CampaignReportSum = new(campaignReportSumService)
|
||||
|
||||
// Create 创建广告计划效果指标表
|
||||
func (s *campaignReportSumService) Create(ctx context.Context, req *dto.CampaignReportSumItem) (res *dto.CreateCampaignReportSumRes, err error) {
|
||||
// 验证必要字段
|
||||
if req.ReportDateStr == "" {
|
||||
return nil, errors.New("报告日期不能为空")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.CampaignReportSum.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.CreateCampaignReportSumRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BatchCreate 批量创建广告计划效果指标表
|
||||
func (s *campaignReportSumService) BatchCreate(ctx context.Context, req *dto.BatchCreateCampaignReportSumReq) (res *dto.BatchCreateCampaignReportSumRes, err error) {
|
||||
ctx = context.WithValue(ctx, "user", &beans.User{UserName: "admin"})
|
||||
// 验证数据
|
||||
if len(req.Items) == 0 {
|
||||
return nil, errors.New("批量创建数据不能为空")
|
||||
}
|
||||
|
||||
// 批量插入数据库
|
||||
successCount, failCount, failedIndexes, err := dao.CampaignReportSum.BatchInsert(ctx, req.Items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.BatchCreateCampaignReportSumRes{
|
||||
SuccessCount: successCount,
|
||||
FailCount: failCount,
|
||||
FailedItems: failedIndexes,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CreateDetail 创建广告效果指标表
|
||||
func (s *campaignReportSumService) CreateDetail(ctx context.Context, req *dto.CampaignReportDetailItem) (res *dto.CreateCampaignReportDetailRes, err error) {
|
||||
// 验证必要字段
|
||||
if req.ReportDateStr == "" {
|
||||
return nil, errors.New("报告日期不能为空")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.CampaignReportDetail.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.CreateCampaignReportDetailRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BatchCreateDetail 批量创建广告效果指标表
|
||||
func (s *campaignReportSumService) BatchCreateDetail(ctx context.Context, req *dto.BatchCreateCampaignReportDetailReq) (res *dto.BatchCreateCampaignReportDetailRes, err error) {
|
||||
ctx = context.WithValue(ctx, "user", &beans.User{UserName: "admin"})
|
||||
// 验证数据
|
||||
if len(req.Items) == 0 {
|
||||
return nil, errors.New("批量创建数据不能为空")
|
||||
}
|
||||
|
||||
// 批量插入数据库
|
||||
successCount, failCount, failedIndexes, err := dao.CampaignReportDetail.BatchInsert(ctx, req.Items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.BatchCreateCampaignReportDetailRes{
|
||||
SuccessCount: successCount,
|
||||
FailCount: failCount,
|
||||
FailedItems: failedIndexes,
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user