task_dto.go 3.9 KB
package dto

import (
	"fmt"
	"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
	"time"
)

type TaskDto struct {
	// 任务ID
	TaskId int64 `json:"taskId"`
	// 公司ID
	CompanyId int64 `json:"companyId"`
	// 任务名称
	TaskName string `json:"taskName"`
	// 任务类型Type
	TaskType int `json:"taskType"`
	// 任务发起者
	Sponsor *domain.EmployeeInfo `json:"sponsor"`
	// 任务状态
	TaskStatus int `json:"taskStatus"`
	// 引用资源
	ReferenceResource *domain.ReferenceResource `json:"referenceResource"`
	// 项目归属
	ProjectBelong *domain.ProjectBelong `json:"projectBelong"`
	// 客户价值列表
	CustomerValues []*domain.CustomerValue `json:"customerValues"`
	// 任务性质
	TaskNature *domain.TaskNature `json:"taskNature"`
	// 奖励素币
	SuMoney float64 `json:"suMoney"`
	// 验收标准
	AcceptanceStandard string `json:"acceptanceStandard"`
	// 任务描述
	TaskDescription string `json:"taskDescription"`
	// 任务图片URL列表
	TaskPictureUrls []string `json:"taskPictureUrls"`
	// 是否悬赏任务
	IsRewardTake bool `json:"isRewardTake"`
	// 抢单任务信息
	RobInfo *domain.RobInfo `json:"robInfo"`
	// 竞标任务信息
	BidInfo *domain.BidInfo `json:"bidInfo"`
	// 任务参与者列表
	Participators []*domain.EmployeeInfo `json:"participators"`
	// 任务贡献占比
	TaskPercentage []*domain.TaskPercentageItem `json:"taskPercentage"`
	// 解决报告
	SolveReport string `json:"solveReport"`
	// 解决图片URL列表
	SolvePictureUrls []string `json:"solvePictureUrls"`
	// 指派人员
	AssignedPerson *domain.EmployeeInfo `json:"assignedPerson"`
	// 计划完成时间
	PlannedCompletionTime time.Time `json:"plannedCompletionTime"`
	// 实际完成时间
	ActualCompletionTime time.Time `json:"actualCompletionTime"`
	// 创建时间
	CreateTime time.Time `json:"createTime"`
	// 发布任务时间
	ReleaseTime time.Time `json:"releaseTime"`
	// 领取任务时间
	ReceiveTime time.Time `json:"receiveTime"`
	// 完成任务操作时间
	CompleteTime time.Time `json:"completeTime"`
	// 验收方验收时间
	AcceptanceTime time.Time `json:"acceptanceTime"`
}

func (dto *TaskDto) LoadDto(task *domain.Task, projectBelongMap map[int]*domain.ProjectBelong, customerValueMap map[int]*domain.CustomerValue, taskNatureMap map[int]*domain.TaskNature) error {
	dto.TaskId = task.TaskId
	dto.CompanyId = task.CompanyId
	dto.TaskName = task.TaskName
	dto.TaskType = task.TaskType
	dto.Sponsor = task.Sponsor
	dto.TaskStatus = task.TaskStatus
	dto.ReferenceResource = task.ReferenceResource
	if task.ProjectBelong != 0 {
		if projectBelong, ok := projectBelongMap[task.ProjectBelong]; ok {
			dto.ProjectBelong = projectBelong
		} else {
			return fmt.Errorf("无效的项目归属")
		}
	}
	if len(task.CustomerValues) > 0 {
		for _, customerValueId := range task.CustomerValues {
			if customerValue, ok := customerValueMap[customerValueId]; ok {
				dto.CustomerValues = append(dto.CustomerValues, customerValue)
			} else {
				return fmt.Errorf("无效的客户价值")
			}
		}
	}
	if task.TaskNature != 0 {
		if taskNature, ok := taskNatureMap[task.TaskNature]; ok {
			dto.TaskNature = taskNature
		} else {
			return fmt.Errorf("无效的任务性质")
		}
	}
	dto.SuMoney = task.SuMoney
	dto.AcceptanceStandard = task.AcceptanceStandard
	dto.TaskDescription = task.TaskDescription
	dto.TaskPictureUrls = task.TaskPictureUrls
	dto.IsRewardTake = task.IsRewardTake
	dto.RobInfo = task.RobInfo
	dto.BidInfo = task.BidInfo
	dto.Participators = task.Participators
	dto.TaskPercentage = task.TaskPercentage
	dto.SolveReport = task.SolveReport
	dto.SolvePictureUrls = task.SolvePictureUrls
	dto.AssignedPerson = task.AssignedPerson
	dto.PlannedCompletionTime = task.PlannedCompletionTime
	dto.ActualCompletionTime = task.ActualCompletionTime
	dto.CreateTime = task.CreateTime
	dto.ReleaseTime = task.ReleaseTime
	dto.ReceiveTime = task.ReceiveTime
	dto.CompleteTime = task.CompleteTime
	dto.AcceptanceTime = task.AcceptanceTime
	return nil
}