代码初始化
This commit is contained in:
97
service/copydata/storewide_report_sum_service.go
Normal file
97
service/copydata/storewide_report_sum_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 storewideReportService struct{}
|
||||
|
||||
// StorewideReportSum 广告效果指标表服务
|
||||
var StorewideReportSum = new(storewideReportService)
|
||||
|
||||
// Create 创建广告效果指标表
|
||||
func (s *storewideReportService) Create(ctx context.Context, req *dto.StorewideReportSumItem) (res *dto.CreateStorewideReportSumRes, err error) {
|
||||
// 验证必要字段
|
||||
if req.ReportDateStr == "" {
|
||||
return nil, errors.New("报告日期不能为空")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.StorewideReportSum.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.CreateStorewideReportSumRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BatchCreate 批量创建广告效果指标表
|
||||
func (s *storewideReportService) BatchCreate(ctx context.Context, req *dto.BatchCreateStorewideReportSumReq) (res *dto.BatchCreateStorewideReportSumRes, 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.StorewideReportSum.BatchInsert(ctx, req.Items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.BatchCreateStorewideReportSumRes{
|
||||
SuccessCount: successCount,
|
||||
FailCount: failCount,
|
||||
FailedItems: failedIndexes,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Create 创建广告效果指标表
|
||||
func (s *storewideReportService) CreateDetail(ctx context.Context, req *dto.StorewideReportDetailItem) (res *dto.CreateStorewideReportDetailRes, err error) {
|
||||
// 验证必要字段
|
||||
if req.ReportDateStr == "" {
|
||||
return nil, errors.New("报告日期不能为空")
|
||||
}
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.StorewideReportDetail.Insert(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.CreateStorewideReportDetailRes{
|
||||
Id: id,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BatchCreate 批量创建广告效果指标表
|
||||
func (s *storewideReportService) BatchCreateDetail(ctx context.Context, req *dto.BatchCreateStorewideReportDetailReq) (res *dto.BatchCreateStorewideReportDetailRes, 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.StorewideReportDetail.BatchInsert(ctx, req.Items)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res = &dto.BatchCreateStorewideReportDetailRes{
|
||||
SuccessCount: successCount,
|
||||
FailCount: failCount,
|
||||
FailedItems: failedIndexes,
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user