114 lines
3.4 KiB
Go
114 lines
3.4 KiB
Go
package copydata
|
|
|
|
import (
|
|
"context"
|
|
dao "dataengine/dao/copydata"
|
|
dto "dataengine/model/dto/copydata"
|
|
entity "dataengine/model/entity/copydata"
|
|
"errors"
|
|
|
|
"gitea.com/red-future/common/beans"
|
|
)
|
|
|
|
type taskReportService struct{}
|
|
|
|
// TaskReport 调控任务数据服务
|
|
var TaskReport = new(taskReportService)
|
|
|
|
// Create 创建调控任务数据
|
|
func (s *taskReportService) Create(ctx context.Context, req *dto.TaskReportItem) (res *dto.CreateTaskReportRes, err error) {
|
|
// 验证必要字段
|
|
if req.ReportDateStr == "" {
|
|
return nil, errors.New("报告日期不能为空")
|
|
}
|
|
|
|
// 插入数据库
|
|
id, err := dao.TaskReport.Insert(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res = &dto.CreateTaskReportRes{
|
|
Id: id,
|
|
}
|
|
return
|
|
}
|
|
|
|
// BatchCreate 批量创建调控任务数据
|
|
func (s *taskReportService) BatchCreate(ctx context.Context, req *dto.BatchCreateTaskReportReq) (res *dto.BatchCreateTaskReportRes, 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.TaskReport.BatchInsert(ctx, req.Items)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res = &dto.BatchCreateTaskReportRes{
|
|
SuccessCount: successCount,
|
|
FailCount: failCount,
|
|
FailedItems: failedIndexes,
|
|
}
|
|
return
|
|
}
|
|
|
|
// List 获取调控任务数据列表
|
|
func (s *taskReportService) List(ctx context.Context, req *dto.ListTaskReportReq) (res *dto.ListTaskReportRes, err error) {
|
|
list, total, err := dao.TaskReport.List(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 转换为 DTO 格式
|
|
items := make([]*dto.TaskReportItem, len(list))
|
|
for i, item := range list {
|
|
items[i] = convertEntityToDTO(item)
|
|
}
|
|
|
|
res = &dto.ListTaskReportRes{
|
|
List: items,
|
|
Total: total,
|
|
}
|
|
return
|
|
}
|
|
|
|
// convertEntityToDTO 将实体转换为 DTO
|
|
func convertEntityToDTO(entity *entity.TaskReport) *dto.TaskReportItem {
|
|
return &dto.TaskReportItem{
|
|
ItemOrderConversionRatio: entity.ItemOrderConversionRatio,
|
|
ItemCardClickRatio: entity.ItemCardClickRatio,
|
|
ItemCardClkCnt: entity.ItemCardClkCnt,
|
|
LivePlayCntCost: entity.LivePlayCntCost,
|
|
AdMerchantFollowCost: entity.AdMerchantFollowCost,
|
|
AdMerchantFollow: entity.AdMerchantFollow,
|
|
NetT0OrderCnt: entity.NetT0OrderCnt,
|
|
NetT0Roi: entity.NetT0Roi,
|
|
NetT0Gmv: entity.NetT0Gmv,
|
|
PhotoName: entity.PhotoName,
|
|
PhotoId: entity.PhotoId,
|
|
CostTotal: entity.CostTotal,
|
|
T0Gmv: entity.T0Gmv,
|
|
T0Roi: entity.T0Roi,
|
|
T0OrderCnt: entity.T0OrderCnt,
|
|
T0OrderCntCost: entity.T0OrderCntCost,
|
|
FansT0Gmv: entity.FansT0Gmv,
|
|
FansT1Gmv: entity.FansT1Gmv,
|
|
FansT7Gmv: entity.FansT7Gmv,
|
|
FansT15Gmv: entity.FansT15Gmv,
|
|
FansT30Gmv: entity.FansT30Gmv,
|
|
FansT0Roi: entity.FansT0Roi,
|
|
FansT1Roi: entity.FansT1Roi,
|
|
FansT7Roi: entity.FansT7Roi,
|
|
FansT15Roi: entity.FansT15Roi,
|
|
FansT30Roi: entity.FansT30Roi,
|
|
LivePlayCnt: entity.LivePlayCnt,
|
|
ItemEntranceClkCnt: entity.ItemEntranceClkCnt,
|
|
ShowCnt: entity.ShowCnt,
|
|
ReportDateStr: entity.ReportDateStr,
|
|
}
|
|
}
|